An XML-RPC server implementation

Example:

use Zend\XmlRpc;

// Instantiate server
$server = new XmlRpc\Server();

// Allow some exceptions to report as fault responses:
XmlRpc\Server\Fault::attachFaultException('My\\Exception');
XmlRpc\Server\Fault::attachObserver('My\\Fault\\Observer');

// Get or build dispatch table:
if (!XmlRpc\Server\Cache::get($filename, $server)) {

    // Attach Some_Service_Class in 'some' namespace
    $server->setClass('Some\\Service\\Class', 'some');

    // Attach Another_Service_Class in 'another' namespace
    $server->setClass('Another\\Service\\Class', 'another');

    // Create dispatch table cache file
    XmlRpc\Server\Cache::save($filename, $server);
}

$response = $server->handle();
echo $response;

 Methods

Proxy calls to system object

__call(string $method, array $params) : mixed

Parameters

$method

string

$params

array

Exceptions

\Zend\XmlRpc\Server\Exception\BadMethodCallException

Returns

mixed

Constructor

__construct() 

Creates system.* methods.

Attach a callback as an XMLRPC method

addFunction(string | array | \Zend\XmlRpc\callable $function, string $namespace) : void

Attaches a callback as an XMLRPC method, prefixing the XMLRPC method name with $namespace, if provided. Reflection is done on the callback's docblock to create the methodHelp for the XMLRPC method.

Additional arguments to pass to the function at dispatch may be passed; any arguments following the namespace will be aggregated and passed at dispatch time.

Parameters

$function

stringarray\Zend\XmlRpc\callable

Valid callback

$namespace

string

Optional namespace prefix

Exceptions

\Zend\XmlRpc\Server\Exception\InvalidArgumentException

Raise an xmlrpc server fault

fault(string | \Exception $fault, int $code) : \Zend\XmlRpc\Server\Fault

Parameters

$fault

string\Exception

$code

int

Returns

Retrieve dispatch table

getDispatchTable() : array

Returns

array

Retrieve current encoding

getEncoding() : string

Returns

string

Returns a list of registered methods

getFunctions() : array

Returns an array of dispatchables (Zend\Server\Reflection\ReflectionFunction, ReflectionMethod, and ReflectionClass items).

Returns

array

Return currently registered request object

getRequest() : null | \Zend\XmlRpc\Request

Returns

Last response.

getResponse() : \Zend\XmlRpc\Response

Retrieve current response class

getResponseClass() : string

Returns

string

Retrieve return response flag

getReturnResponse() : bool

Returns

bool

Retrieve system object

getSystem() : \Zend\XmlRpc\Server\System

Handle an xmlrpc call

handle(\Zend\XmlRpc\Request $request) : \Zend\XmlRpc\Response | \Zend\XmlRpc\Fault

Requests may be passed in, or the server may automatically determine the request based on defaults. Dispatches server request to appropriate method and returns a response

Parameters

$request

\Zend\XmlRpc\Request

Optional

Returns

Load methods as returned from {@link getFunctions}

loadFunctions(array | \Zend\Server\Definition $definition) : void

Typically, you will not use this method; it will be called using the results pulled from Zend\XmlRpc\Server\Cache::get().

Parameters

$definition

array\Zend\Server\Definition

Exceptions

\Zend\XmlRpc\Server\Exception\InvalidArgumentException on invalid input

Send arguments to all methods?

sendArgumentsToAllMethods($flag) 

If setClass() is used to add classes to the server, this flag defined how to handle arguments. If set to true, all methods including constructor will receive the arguments. If set to false, only constructor will receive the arguments

Parameters

$flag

Attach class methods as XMLRPC method handlers

setClass(string | object $class, string $namespace, mixed $argv) : void

$class may be either a class name or an object. Reflection is done on the class or object to determine the available public methods, and each is attached to the server as an available method; if a $namespace has been provided, that namespace is used to prefix the XMLRPC method names.

Any additional arguments beyond $namespace will be passed to a method at invocation.

Parameters

$class

stringobject

$namespace

string

Optional

$argv

mixed

Optional arguments to pass to methods

Exceptions

\Zend\XmlRpc\Server\Exception\InvalidArgumentException on invalid input

Set encoding

setEncoding(string $encoding) : \Zend\XmlRpc\Server

Parameters

$encoding

string

Returns

Do nothing; persistence is handled via {@link Zend\XmlRpc\Server\Cache}

setPersistence(mixed $mode) : void

Parameters

$mode

mixed

Set the request object

setRequest(string | \Zend\XmlRpc\Request $request) : \Zend\XmlRpc\Server

Parameters

$request

string\Zend\XmlRpc\Request

Exceptions

\Zend\XmlRpc\Server\Exception\InvalidArgumentException on invalid request class or object

Returns

Set the class to use for the response

setResponseClass(string $class) : bool

Parameters

$class

string

Exceptions

\Zend\XmlRpc\Server\Exception\InvalidArgumentException if invalid response class

Returns

boolTrue if class was set, false if not

Set return response flag

setReturnResponse(bool $flag) : \Zend\XmlRpc\Server

If true, handle() will return the response instead of automatically sending it back to the requesting client.

The response is always available via getResponse().

Parameters

$flag

bool

Returns

Build callback for method signature

_buildCallback(\Zend\Server\Reflection\AbstractFunction $reflection) : \Zend\Server\Method\Callback
Inherited

inherited_from \Zend\Server\AbstractServer::_buildCallback()

Parameters

Returns

Build a method signature

_buildSignature(\Zend\Server\Reflection\AbstractFunction $reflection, null | string | object $class) : \Zend\Server\Method\Definition
Inherited

inherited_from \Zend\Server\AbstractServer::_buildSignature()

Parameters

$class

nullstringobject

Exceptions

\Zend\Server\Exception\RuntimeException on duplicate entry

Returns

Dispatch method

_dispatch(\Zend\Server\Method\Definition $invokable, array $params) : mixed
Inherited

inherited_from \Zend\Server\AbstractServer::_dispatch()

Parameters

$params

array

Returns

mixed

Map PHP type to XML-RPC type

_fixType(string $type) : string

Parameters

$type

string

Returns

string

Handle an xmlrpc call (actual work)

handleRequest(\Zend\XmlRpc\Request $request) : \Zend\XmlRpc\Response

Parameters

Exceptions

\Zend\XmlRpc\Server\Exception\RuntimeException Zend\XmlRpc\Server\Exceptions are thrown for internal errors; otherwise, any other exception may be thrown by the callback

Returns

Checks if the object has this class as one of its parents

isSubclassOf(string $className, string $type) : bool

see \Zend\XmlRpc\https://bugs.php.net/bug.php?id=53727
see \Zend\XmlRpc\https://github.com/zendframework/zf2/pull/1807

Parameters

$className

string

$type

string

Returns

bool

Register system methods with the server

registerSystemMethods() : void

 Properties

 

Character encoding

$encoding : string

 

<p>Flag; whether or not overwriting existing methods is allowed</p>

$overwriteExistingMethods : bool
Inherited

inherited_from \Zend\Server\AbstractServer::$$overwriteExistingMethods
 

Request processed

$request : null | \Zend\XmlRpc\Request

 

Last response results.

$response : \Zend\XmlRpc\Response

 

Class to use for responses; defaults to {@link Response\Http}

$responseClass : string

 

Flag: whether or not {@link handle()} should return a response instead of automatically emitting it.

$returnResponse : bool

 

Send arguments to all methods or just constructor?

$sendArgumentsToAllMethods : bool

 

Dispatch table of name => method pairs

$table : \Zend\Server\Definition

 

PHP types => XML-RPC types

$typeMap : array