Server
in package
uses
CharsetEncoderAware, DeprecationLogger, ParserAware
Allows effortless implementation of XML-RPC servers
Table of Contents
Constants
- OPT_ACCEPTED_COMPRESSION = 'accepted_compression'
- OPT_ALLOW_SYSTEM_FUNCS = 'allow_system_funcs'
- OPT_COMPRESS_RESPONSE = 'compress_response'
- OPT_DEBUG = 'debug'
- OPT_EXCEPTION_HANDLING = 'exception_handling'
- OPT_FUNCTIONS_PARAMETERS_TYPE = 'functions_parameters_type'
- OPT_PHPVALS_ENCODING_OPTIONS = 'phpvals_encoding_options'
- OPT_RESPONSE_CHARSET_ENCODING = 'response_charset_encoding'
Properties
- $accepted_compression : array<string|int, string>
- $allow_system_funcs : bool
- $compress_response : bool
- $debug : int
- $exception_handling : int
- $functions_parameters_type : string
- $phpvals_encoding_options : array<string|int, mixed>
- $response_charset_encoding : string
- $_xmlrpc_debuginfo : mixed
- $_xmlrpcs_occurred_errors : mixed
- $_xmlrpcs_prev_ehandler : mixed
- $accepted_compression : array<string|int, string>
- $allow_system_funcs : bool
- $charsetEncoder : mixed
- $compress_response : bool
- $debug : int
- $debug_info : mixed
- Storage for internal debug info.
- $dmap : array<string|int, array<string|int, mixed>>
- Array defining php functions exposed as xml-rpc methods by this server.
- $exception_handling : int
- $functions_parameters_type : string
- $options : mixed
- $parser : mixed
- $phpvals_encoding_options : array<string|int, mixed>
- $response_charset_encoding : string
- $responseClass : string
- $accepted_charset_encodings : mixed
- List of charset encodings natively accepted for requests.
Methods
- __construct() : mixed
- __get() : mixed
- __isset() : mixed
- __set() : mixed
- __unset() : mixed
- add_to_map() : void
- Add a method to the dispatch map.
- addToMap() : void
- Add a method to the dispatch map.
- error_occurred() : void
- Add a string to the debug info that will be later serialized by the server as part of the response message (base64 encoded) when debug level >= 2
- getCapabilities() : array<string|int, array<string|int, mixed>>
- getCharsetEncoder() : mixed
- getDispatchMap() : array<string|int, array<string|int, mixed>>
- getOption() : mixed
- getOptions() : array<string|int, mixed>
- Returns the complete list of Server options.
- getParser() : mixed
- getSystemDispatchMap() : array<string|int, array<string|int, mixed>>
- service() : Response|string
- Execute the xml-rpc request, printing the response.
- setCharsetEncoder() : void
- setDebug() : $this
- Set debug level of server.
- setDispatchMap() : $this
- setOption() : $this
- setOptions() : $this
- setParser() : void
- xmlrpc_debugmsg() : void
- Add a string to the debug info that can be later serialized by the server as part of the response message.
- debugMsg() : void
- Add a string to the 'internal debug message' (separate from 'user debug message').
- execute() : Response
- Execute a method invoked by the client, checking parameters used.
- isSyscall() : bool
- logDeprecation() : mixed
- logDeprecationUnlessCalledBy() : void
- parseRequestHeaders() : Response|null
- Parse http headers received along with xml-rpc request. If needed, inflate request.
- verifySignature() : array<string|int, mixed>
- Verify type and number of parameters received against a list of known signatures.
- xml_header() : string
Constants
OPT_ACCEPTED_COMPRESSION
public
mixed
OPT_ACCEPTED_COMPRESSION
= 'accepted_compression'
OPT_ALLOW_SYSTEM_FUNCS
public
mixed
OPT_ALLOW_SYSTEM_FUNCS
= 'allow_system_funcs'
OPT_COMPRESS_RESPONSE
public
mixed
OPT_COMPRESS_RESPONSE
= 'compress_response'
OPT_DEBUG
public
mixed
OPT_DEBUG
= 'debug'
OPT_EXCEPTION_HANDLING
public
mixed
OPT_EXCEPTION_HANDLING
= 'exception_handling'
OPT_FUNCTIONS_PARAMETERS_TYPE
public
mixed
OPT_FUNCTIONS_PARAMETERS_TYPE
= 'functions_parameters_type'
OPT_PHPVALS_ENCODING_OPTIONS
public
mixed
OPT_PHPVALS_ENCODING_OPTIONS
= 'phpvals_encoding_options'
OPT_RESPONSE_CHARSET_ENCODING
public
mixed
OPT_RESPONSE_CHARSET_ENCODING
= 'response_charset_encoding'
Properties
$accepted_compression
public
array<string|int, string>
$accepted_compression
deprecated - public access left in purely for BC. Access via getOption()/setOption()
$allow_system_funcs
public
bool
$allow_system_funcs
deprecated - public access left in purely for BC. Access via getOption()/setOption()
$compress_response
public
bool
$compress_response
deprecated - public access left in purely for BC. Access via getOption()/setOption()
$debug
public
int
$debug
deprecated - public access left in purely for BC. Access via getOption()/setOption()
$exception_handling
public
int
$exception_handling
deprecated - public access left in purely for BC. Access via getOption()/setOption()
$functions_parameters_type
public
string
$functions_parameters_type
deprecated - public access left in purely for BC. Access via getOption()/setOption()
$phpvals_encoding_options
public
array<string|int, mixed>
$phpvals_encoding_options
deprecated - public access left in purely for BC. Access via getOption()/setOption()
$response_charset_encoding
public
string
$response_charset_encoding
deprecated - public access left in purely for BC. Access via getOption()/setOption()
$_xmlrpc_debuginfo
protected
static mixed
$_xmlrpc_debuginfo
= ''
$_xmlrpcs_occurred_errors
protected
static mixed
$_xmlrpcs_occurred_errors
= ''
$_xmlrpcs_prev_ehandler
protected
static mixed
$_xmlrpcs_prev_ehandler
= ''
$accepted_compression
protected
array<string|int, string>
$accepted_compression
= array()
List of http compression methods accepted by the server for requests. Automatically set at constructor time. NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
$allow_system_funcs
protected
bool
$allow_system_funcs
= true
Shall we serve calls to system.* methods?
$charsetEncoder
protected
static mixed
$charsetEncoder
$compress_response
protected
bool
$compress_response
= false
When set to true, it will enable HTTP compression of the response, in case the client has declared its support for compression in the request. Automatically set at constructor time.
$debug
protected
int
$debug
= 1
Controls whether the server is going to echo debugging messages back to the client as comments in response body. SECURITY SENSITIVE! Valid values: 0 = 1 = 2 = 3 =
$debug_info
Storage for internal debug info.
protected
mixed
$debug_info
= ''
$dmap
Array defining php functions exposed as xml-rpc methods by this server.
protected
array<string|int, array<string|int, mixed>>
$dmap
= array()
$exception_handling
protected
int
$exception_handling
= 0
Controls behaviour of server when the invoked method-handler function throws an exception (within the execute
method):
0 = catch it and return an 'internal error' xml-rpc response (default)
1 = SECURITY SENSITIVE DO NOT ENABLE ON PUBLIC SERVERS!!! catch it and return an xml-rpc response with the error
corresponding to the exception, both its code and message.
2 = allow the exception to float to the upper layers
Can be overridden per-method-handler in the dispatch map
$functions_parameters_type
protected
string
$functions_parameters_type
= 'xmlrpcvals'
Defines how functions in $dmap will be invoked: either using an xml-rpc Request object or plain php values. Valid strings are 'xmlrpcvals', 'phpvals' or 'epivals' (the latter only for use by polyfill-xmlrpc).
Tags
$options
protected
static mixed
$options
= array(self::OPT_ACCEPTED_COMPRESSION, self::OPT_ALLOW_SYSTEM_FUNCS, self::OPT_COMPRESS_RESPONSE, self::OPT_DEBUG, self::OPT_EXCEPTION_HANDLING, self::OPT_FUNCTIONS_PARAMETERS_TYPE, self::OPT_PHPVALS_ENCODING_OPTIONS, self::OPT_RESPONSE_CHARSET_ENCODING)
$parser
protected
static mixed
$parser
$phpvals_encoding_options
protected
array<string|int, mixed>
$phpvals_encoding_options
= array('auto_dates')
Option used for fine-tuning the encoding the php values returned from functions registered in the dispatch map when the functions_parameters_type member is set to 'phpvals'.
Tags
$response_charset_encoding
protected
string
$response_charset_encoding
= ''
Charset encoding to be used for response. NB: if we can, we will convert the generated response from internal_encoding to the intended one. Can be:
- a supported xml encoding (only UTF-8 and ISO-8859-1, unless mbstring is enabled),
- null (leave unspecified in response, convert output stream to US_ASCII),
- 'auto' (use client-specified charset encoding or same as request if request headers do not specify it (unless request is US-ASCII: then use library default anyway). NB: pretty dangerous if you accept every charset and do not have mbstring enabled)
$responseClass
protected
static string
$responseClass
= '\PhpXmlRpc\Response'
$accepted_charset_encodings
List of charset encodings natively accepted for requests.
UNUSED so far by this library. It is still accessible by subclasses but will be dropped in the future.
private
mixed
$accepted_charset_encodings
= array()
Set at constructor time.
Methods
__construct()
public
__construct([array<string|int, array<string|int, mixed>> $dispatchMap = null ][, bool $serviceNow = true ]) : mixed
Parameters
- $dispatchMap : array<string|int, array<string|int, mixed>> = null
-
the dispatch map with definition of exposed services Array keys are the names of the method names. Each array value is an array with the following members:
- function (callable)
- docstring (optional)
- signature (array, optional)
- signature_docs (array, optional)
- parameters_type (string, optional). Valid values: 'phpvals', 'xmlrpcvals'
- exception_handling (int, optional)
- $serviceNow : bool = true
-
set to false in order to prevent the server from running upon construction
__get()
public
& __get(mixed $name) : mixed
Parameters
- $name : mixed
__isset()
public
__isset(mixed $name) : mixed
Parameters
- $name : mixed
__set()
public
__set(mixed $name, mixed $value) : mixed
Parameters
- $name : mixed
- $value : mixed
__unset()
public
__unset(mixed $name) : mixed
Parameters
- $name : mixed
add_to_map()
Add a method to the dispatch map.
public
add_to_map(string $methodName, callable $function[, array<string|int, array<string|int, mixed>> $sig = null ][, string $doc = false ][, array<string|int, array<string|int, mixed>> $sigDoc = false ][, string $parametersType = false ][, int $exceptionHandling = false ]) : void
use addToMap instead
Parameters
- $methodName : string
-
the name with which the method will be made available
- $function : callable
-
the php function that will get invoked
- $sig : array<string|int, array<string|int, mixed>> = null
-
the array of valid method signatures. Each element is one signature: an array of strings with at least one element First element = type of returned value. Elements 2..N = types of parameters 1..N
- $doc : string = false
-
method documentation
- $sigDoc : array<string|int, array<string|int, mixed>> = false
-
the array of valid method signatures docs, following the format of $sig but with descriptions instead of types (one string for return type, one per param)
- $parametersType : string = false
-
to allow single method handlers to receive php values instead of a Request, or vice-versa
- $exceptionHandling : int = false
-
@see $this->exception_handling
Tags
addToMap()
Add a method to the dispatch map.
public
addToMap(string $methodName, callable $function[, array<string|int, array<string|int, mixed>> $sig = null ][, string $doc = false ][, array<string|int, array<string|int, mixed>> $sigDoc = false ][, string $parametersType = false ][, int $exceptionHandling = false ]) : void
Parameters
- $methodName : string
-
the name with which the method will be made available
- $function : callable
-
the php function that will get invoked
- $sig : array<string|int, array<string|int, mixed>> = null
-
the array of valid method signatures. Each element is one signature: an array of strings with at least one element First element = type of returned value. Elements 2..N = types of parameters 1..N
- $doc : string = false
-
method documentation
- $sigDoc : array<string|int, array<string|int, mixed>> = false
-
the array of valid method signatures docs, following the format of $sig but with descriptions instead of types (one string for return type, one per param)
- $parametersType : string = false
-
to allow single method handlers to receive php values instead of a Request, or vice-versa
- $exceptionHandling : int = false
-
@see $this->exception_handling
Tags
error_occurred()
Add a string to the debug info that will be later serialized by the server as part of the response message (base64 encoded) when debug level >= 2
public
static error_occurred(string $msg) : void
Parameters
- $msg : string
getCapabilities()
public
getCapabilities() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>getCharsetEncoder()
public
getCharsetEncoder() : mixed
getDispatchMap()
public
getDispatchMap() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>getOption()
public
getOption(string $name) : mixed
Parameters
- $name : string
-
see all the OPT_ constants
Tags
getOptions()
Returns the complete list of Server options.
public
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getParser()
public
getParser() : mixed
getSystemDispatchMap()
public
getSystemDispatchMap() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>service()
Execute the xml-rpc request, printing the response.
public
service([string $data = null ][, bool $returnPayload = false ]) : Response|string
Parameters
- $data : string = null
-
the request body. If null, the http POST request will be examined
- $returnPayload : bool = false
-
When true, return the response but do not echo it or any http header
Tags
Return values
Response|string —the response object (usually not used by caller...) or its xml serialization
setCharsetEncoder()
public
static setCharsetEncoder(mixed $charsetEncoder) : void
Parameters
- $charsetEncoder : mixed
setDebug()
Set debug level of server.
public
setDebug(int $level) : $this
Parameters
- $level : int
-
debug lvl: determines info added to xml-rpc responses (as xml comments) 0 = no debug info, 1 = msgs set from user with debugmsg(), 2 = add complete xml-rpc request (headers and body), 3 = add also all processing warnings happened during method processing (NB: this involves setting a custom error handler, and might interfere with the standard processing of the php function exposed as method. In particular, triggering a USER_ERROR level error will not halt script execution anymore, but just end up logged in the xml-rpc response) Note that info added at level 2 and 3 will be base64 encoded
Return values
$thissetDispatchMap()
public
setDispatchMap(array<string|int, mixed> $dmap) : $this
Parameters
- $dmap : array<string|int, mixed>
Return values
$thissetOption()
public
setOption(string $name, mixed $value) : $this
Parameters
- $name : string
-
see all the OPT_ constants
- $value : mixed
Tags
Return values
$thissetOptions()
public
setOptions(array<string|int, mixed> $options) : $this
Parameters
- $options : array<string|int, mixed>
-
key: see all the OPT_ constants
Tags
Return values
$thissetParser()
public
static setParser(mixed $parser) : void
Parameters
- $parser : mixed
xmlrpc_debugmsg()
Add a string to the debug info that can be later serialized by the server as part of the response message.
public
static xmlrpc_debugmsg(string $msg) : void
Note that for best compatibility, the debug string should be encoded using the PhpXmlRpc::$xmlrpc_internalencoding character set.
Parameters
- $msg : string
debugMsg()
Add a string to the 'internal debug message' (separate from 'user debug message').
protected
debugMsg(string $string) : void
Parameters
- $string : string
execute()
Execute a method invoked by the client, checking parameters used.
protected
execute(Request|string $req[, array<string|int, mixed> $params = null ][, array<string|int, string> $paramTypes = null ]) : Response
Parameters
- $req : Request|string
-
either a Request obj or a method name
- $params : array<string|int, mixed> = null
-
array with method parameters as php types (only if $req is method name)
- $paramTypes : array<string|int, string> = null
-
array with xml-rpc types of method parameters (only if $req is method name)
Tags
Return values
ResponseisSyscall()
protected
isSyscall(string $methName) : bool
Parameters
- $methName : string
Return values
boollogDeprecation()
protected
logDeprecation(mixed $message) : mixed
Parameters
- $message : mixed
logDeprecationUnlessCalledBy()
protected
logDeprecationUnlessCalledBy(string $expectedCaller) : void
Parameters
- $expectedCaller : string
-
atm only the method name is supported
parseRequestHeaders()
Parse http headers received along with xml-rpc request. If needed, inflate request.
protected
parseRequestHeaders(mixed &$data, mixed &$reqEncoding, mixed &$respEncoding, mixed &$respCompression) : Response|null
Parameters
- $data : mixed
- $reqEncoding : mixed
- $respEncoding : mixed
- $respCompression : mixed
Return values
Response|null —null on success or an error Response
verifySignature()
Verify type and number of parameters received against a list of known signatures.
protected
verifySignature(array<string|int, mixed>|Request $in, array<string|int, mixed> $sigs) : array<string|int, mixed>
Parameters
- $in : array<string|int, mixed>|Request
-
array of either xml-rpc value objects or xml-rpc type definitions
- $sigs : array<string|int, mixed>
-
array of known signatures to match against
Return values
array<string|int, mixed> —int, string
xml_header()
protected
xml_header([string $charsetEncoding = '' ]) : string
this method was moved to the Response class
Parameters
- $charsetEncoding : string = ''