An example of using this feature has been added to demo file `windowscharset.php`
+* new: allow the library to pass to the application DateTime objects instead of string for all received dateTime.iso8601
+ xml-rpc values. This includes both client-side, for data with the `$response->value()`, and server-side, for data
+ passed to xml-rpc method handlers, and works both in 'xmlrpcvals' and in 'phpvals' modes.
+ In order to enable this, you can set `PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true`.
+ NB: since the xml-rpc spec mandates that no Timezone is used on the wire for dateTime values, the DateTime objects
+ created by the library will be set to the default php timzeone, set using the 'date.timezone' ini setting.
+
* fixed: when calling `Client::multicall()` with `$client->return_type = 'xml'`, we would be always falling back to
non-multicall requests
dateTime.iso8601 is supported opaquely, largely for historical reasons. Datetime conversion can't be done transparently
as the XML-RPC specification explicitly forbids passing of timezone specifiers in ISO8601 format dates. You can, however,
-use the `PhpXmlRpc\Helper\Date` class to do the encoding and decoding for you.
+use the `PhpXmlRpc\Helper\Date` class to do the encoding and decoding for you, or force usage of DateTime objects via
+the `PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes` variable.
Most class members have "public" access, even those only meant for internal usage.
used as source values. For those, the original value will be returned when calling `+$value->scalarval();+`.
When Value objects are created by the library by parsing some received XML text, all Value objects representing an xml-rpc
-dateTime.iso8601 value will return the string representation of the date when calling `+$value->scalarval();+`.
+dateTime.iso8601 value will by default return the string representation of the date when calling `+$value->scalarval();+`.
Datetime conversion can't be safely done in a transparent manner as the XML-RPC specification explicitly forbids passing
-of timezone specifiers in ISO8601 format dates. You can, however, use the `PhpXmlRpc\Helper\Date` class to decode the date
-string into a unix timestamp, or use the `PhpXmlRpc\Encoder::decode` method with the 'dates_as_objects' option to get
-back a php DateTime (in which case the conversion is done using the `strtotime` function, which uses the timezone set in
-php.ini).
+of timezone specifiers in ISO8601 format dates. You can, however, use multiple techniques to transform the date string
+into another representation of a time stamp:
+* use the `PhpXmlRpc\Helper\Date` class to decode the date string into a unix timestamp;
+* set `PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true` to always get back a php DateTime from received xml (in
+ which case the conversion is done using the timezone set in php.ini).
+* use the `PhpXmlRpc\Encoder::decode` method with the 'dates_as_objects' option to get back a php DateTime (in which case
+ the conversion is done using the `strtotime` function, which uses the timezone set in php.ini).
===== double
/**
* @var bool
*
- * This determines whether the multicall() method will try to take advantage of the system.multicall xmlrpc method
+ * This determines whether the multicall() method will try to take advantage of the system.multicall xml-rpc method
* to dispatch to the server an array of requests in a single http roundtrip or simply execute many consecutive http
* calls. Defaults to FALSE, but it will be enabled automatically on the first failure of execution of
* system.multicall.
* Response objects in any case.
* Note that the 'phpvals' setting will yield faster execution times, but some of the information from the original
* response will be lost. It will be e.g. impossible to tell whether a particular php string value was sent by the
- * server as an xmlrpc string or base64 value.
+ * server as an xml-rpc string or base64 value.
*/
public $return_type = XMLParser::RETURN_XMLRPCVALS;
}
/**
- * @param string $path either the PATH part of the xmlrpc server URL, or complete server URL (in which case you
+ * @param string $path either the PATH part of the xml-rpc server URL, or complete server URL (in which case you
* should use and empty string for all other parameters)
* e.g. /xmlrpc/server.php
* e.g. http://phpxmlrpc.sourceforge.net/server.php
}
/**
- * Enable/disable the echoing to screen of the xmlrpc responses received. The default is not to output anything.
+ * Enable/disable the echoing to screen of the xml-rpc responses received. The default is not to output anything.
*
* The debugging information at level 1 includes the raw data returned from the XML-RPC server it was querying
* (including bot HTTP headers and the full XML payload), and the PHP value the client attempts to create to
* represent the value returned by the server.
- * At level2, the complete payload of the xmlrpc request is also printed, before being sent to the server.
+ * At level2, the complete payload of the xml-rpc request is also printed, before being sent to the server.
*
* This option can be very useful when debugging servers as it allows you to see exactly what the client sends and
* the server returns. Never leave it enabled for production!
}
/**
- * Enables/disables reception of compressed xmlrpc responses.
+ * Enables/disables reception of compressed xml-rpc responses.
*
* This requires the "zlib" extension to be enabled in your php install. If it is, by default xmlrpc_client
* instances will enable reception of compressed content.
- * Note that enabling reception of compressed responses merely adds some standard http headers to xmlrpc requests.
- * It is up to the xmlrpc server to return compressed responses when receiving such requests.
+ * Note that enabling reception of compressed responses merely adds some standard http headers to xml-rpc requests.
+ * It is up to the xml-rpc server to return compressed responses when receiving such requests.
*
* @param string $compMethod either 'gzip', 'deflate', 'any' or ''
* @return $this
}
/**
- * Enables/disables http compression of xmlrpc request.
+ * Enables/disables http compression of xml-rpc request.
*
* This requires the "zlib" extension to be enabled in your php install.
* Take care when sending compressed requests: servers might not support them (and automatic fallback to
}
/**
- * Send an xmlrpc request to the server.
+ * Send an xml-rpc request to the server.
*
* @param Request|Request[]|string $req The Request object, or an array of requests for using multicall, or the
* complete xml representation of a request.
* a single 'system.multicall' xml-rpc method call to forward to the server all
* the requests in a single HTTP round trip, unless $this->no_multicall has
* been previously set to TRUE (see the multicall method below), in which case
- * many consecutive xmlrpc requests will be sent. The method will return an
+ * many consecutive xml-rpc requests will be sent. The method will return an
* array of Response objects in both cases.
* The third variant allows to build by hand (or any other means) a complete
- * xmlrpc request message, and send it to the server. $req should be a string
+ * xml-rpc request message, and send it to the server. $req should be a string
* containing the complete xml representation of the request. It is e.g. useful
* when, for maximal speed of execution, the request is serialized into a
- * string using the native php xmlrpc functions (see http://www.php.net/xmlrpc)
+ * string using the native php xml-rpc functions (see http://www.php.net/xmlrpc)
* @param integer $timeout deprecated. Connection timeout, in seconds, If unspecified, the timeout set with setTimeout
* will be used. If that is 0, a platform specific timeout will apply.
* This timeout value is passed to fsockopen(). It is also used for detecting server
/**
* Send an array of requests and return an array of responses.
*
- * Unless $this->no_multicall has been set to true, it will try first to use one single xmlrpc call to server method
+ * Unless $this->no_multicall has been set to true, it will try first to use one single xml-rpc call to server method
* system.multicall, and revert to sending many successive calls in case of failure.
* This failure is also stored in $this->no_multicall for subsequent calls.
* Unfortunately, there is no server error code universally used to denote the fact that multicall is unsupported,
}
/**
- * Takes an xmlrpc Value in object instance and translates it into native PHP types, recursively.
- * Works with xmlrpc Request objects as input, too.
+ * Takes an xml-rpc Value in object instance and translates it into native PHP types, recursively.
+ * Works with xml-rpc Request objects as input, too.
* Xmlrpc dateTime values will be converted to strings or DateTime objects depending on an $options parameter
- * Supports i8 and NIL xmlrpc values without the need for specific options.
- * Both xmlrpc arrays and structs are decoded into PHP arrays, with the exception described below:
+ * Supports i8 and NIL xml-rpc values without the need for specific options.
+ * Both xml-rpc arrays and structs are decoded into PHP arrays, with the exception described below:
* Given proper options parameter, can rebuild generic php object instances (provided those have been encoded to
- * xmlrpc format using a corresponding option in php_xmlrpc_encode()).
+ * xml-rpc format using a corresponding option in php_xmlrpc_encode()).
* PLEASE NOTE that rebuilding php objects involves calling their constructor function.
* This means that the remote communication end can decide which php code will get executed on your server, leaving
* the door possibly open to 'php-injection' style of attacks (provided you have some classes defined on your server
*
* @param Value|Request $xmlrpcVal
* @param array $options accepted elements:
- * - 'decode_php_objs': if set in the options array, xmlrpc structs can be decoded into php
+ * - 'decode_php_objs': if set in the options array, xml-rpc structs can be decoded into php
* objects, see the details above;
- * - 'dates_as_objects': when set xmlrpc dateTimes are decoded as php DateTime objects
+ * - 'dates_as_objects': when set xml-rpc dateTimes are decoded as php DateTime objects
* - 'extension_api': reserved for usage by phpxmlrpc-polyfill
* @return mixed
*
- * Feature creep -- add an option to allow converting xmlrpc dateTime values to unix timestamps (integers)
+ * Feature creep -- add an option to allow converting xml-rpc dateTime values to unix timestamps (integers)
*/
public function decode($xmlrpcVal, $options = array())
{
}
}
if (in_array('dates_as_objects', $options) && $xmlrpcVal->scalartyp() == 'dateTime.iso8601') {
- // we return a Datetime object instead of a string since now the constructor of xmlrpc value accepts
+ // we return a Datetime object instead of a string since now the constructor of xml-rpc value accepts
// safely string, int and DateTimeInterface, we cater to all 3 cases here
$out = $xmlrpcVal->scalarval();
if (is_string($out)) {
case 'struct':
// If user said so, try to rebuild php objects for specific struct vals.
/// @todo should we raise a warning for class not found?
- // shall we check for proper subclass of xmlrpc value instead of presence of _php_class to detect
+ // shall we check for proper subclass of xml-rpc value instead of presence of _php_class to detect
// what we can do?
if (in_array('decode_php_objs', $options) && $xmlrpcVal->_php_class != ''
&& class_exists($xmlrpcVal->_php_class)
}
/**
- * Takes native php types and encodes them into xmlrpc Value objects, recursively.
+ * Takes native php types and encodes them into xml-rpc Value objects, recursively.
* PHP strings, integers, floats and booleans have a straightforward encoding - note that integers will _not_ be
- * converted to xmlrpc <i8> elements, even if they exceed the 32-bit range.
- * PHP arrays will be encoded to either xmlrpc structs or arrays, depending on whether they are hashes
+ * converted to xml-rpc <i8> elements, even if they exceed the 32-bit range.
+ * PHP arrays will be encoded to either xml-rpc structs or arrays, depending on whether they are hashes
* or plain 0..N integer indexed.
- * PHP objects will be encoded into xmlrpc structs, except if they implement DateTimeInterface, in which case they
+ * PHP objects will be encoded into xml-rpc structs, except if they implement DateTimeInterface, in which case they
* will be encoded as dateTime values.
* PhpXmlRpc\Value objects will not be double-encoded - which makes it possible to pass in a pre-created base64 Value
* as part of a php array.
- * If given a proper $options parameter, php object instances will be encoded into 'special' xmlrpc values, that can
+ * If given a proper $options parameter, php object instances will be encoded into 'special' xml-rpc values, that can
* later be decoded into php object instances by calling php_xmlrpc_decode() with a corresponding option.
* PHP resource and NULL variables will be converted into uninitialized Value objects (which will lead to invalid
- * xmlrpc when later serialized); to support encoding of the latter use the appropriate $options parameter.
+ * xml-rpc when later serialized); to support encoding of the latter use the appropriate $options parameter.
*
* @author Dan Libby (dan@libby.com)
*
- * @param mixed $phpVal the value to be converted into an xmlrpc value object
+ * @param mixed $phpVal the value to be converted into an xml-rpc value object
* @param array $options can include:
* - 'encode_php_objs' when set, some out-of-band info will be added to the xml produced by
* serializing the built Value, which can later be decoced by this library to rebuild an
* instance of the same php object
- * - 'auto_dates': when set, any string which respects the xmlrpc datetime format will be converted to a dateTime Value
- * - 'null_extension': when set, php NULL values will be converted to an xmlrpc <NIL> (or <EX:NIL>) Value
+ * - 'auto_dates': when set, any string which respects the xml-rpc datetime format will be converted to a dateTime Value
+ * - 'null_extension': when set, php NULL values will be converted to an xml-rpc <NIL> (or <EX:NIL>) Value
* - 'extension_api': reserved for usage by phpxmlrpc-polyfill
* @return Value
*
}
$xmlrpcVal = new Value($arr, Value::$xmlrpcStruct);
if (in_array('encode_php_objs', $options)) {
- // let's save original class name into xmlrpc value: it might be useful later on...
+ // let's save original class name into xml-rpc value: it might be useful later on...
$xmlrpcVal->_php_class = get_class($phpVal);
}
}
/**
* Convert the xml representation of a method response, method request or single
- * xmlrpc value into the appropriate object (a.k.a. deserialize).
+ * xml-rpc value into the appropriate object (a.k.a. deserialize).
*
* @param string $xmlVal
* @param array $options unused atm
case 'UTF-8_ISO-8859-1':
// NB: this will choke on invalid UTF-8, going most likely beyond EOF
$escapedData = '';
- // be kind to users creating string xmlrpc values out of different php types
+ // be kind to users creating string xml-rpc values out of different php types
$data = (string)$data;
$ns = strlen($data);
for ($nn = 0; $nn < $ns; $nn++) {
* @param string $idate
* @param bool|int $utc either 0 (assume date is in local time) or 1 (assume date is in UTC)
*
- * @return int (timestamp) 0 if the source string does not match the xmlrpc dateTime format
+ * @return int (timestamp) 0 if the source string does not match the xml-rpc dateTime format
*/
public static function iso8601Decode($idate, $utc = 0)
{
* Quick explanation of components:
* private:
* ac - used to accumulate values
- * stack - array with genealogy of xml elements names, used to validate nesting of xmlrpc elements
+ * stack - array with genealogy of xml elements names, used to validate nesting of xml-rpc elements
* valuestack - array used for parsing arrays and structs
* lv - used to indicate "looking for a value": implements the logic to allow values with no types to be strings
* (values: 0=not looking, 1=looking, 3=found)
}
/**
- * @param array $options passed to the xml parser
+ * @param array $options integer keys: options passed to the xml parser
+ * string keys: target_charset, methodname_callback, xmlrpc_null_extension, xmlrpc_return_datetimes
*/
public function __construct(array $options = array())
{
* @param string $data
* @param string $returnType self::RETURN_XMLRPCVALS, self::RETURN_PHP, self::RETURN_EPIVALS
* @param int $accept a bit-combination of self::ACCEPT_REQUEST, self::ACCEPT_RESPONSE, self::ACCEPT_VALUE
- * @param array $options integer-key options are passed to the xml parser, in addition to the options received in
- * the constructor. String-key options are used independently
+ * @param array $options integer-key options are passed to the xml parser, string-key options are used independently.
+ * These options are the options received in the constructor.
* @return void the caller has to look into $this->_xh to find the results
* @throws \Exception this can happen if a callback function is set and it does throw (i.e. we do not catch exceptions)
*
}
foreach ($mergedOptions as $key => $val) {
+ // q: can php be built without ctype? should we use a regexp?
if (is_string($key) && !ctype_digit($key)) {
switch($key) {
case 'target_charset':
}
break;
+ case 'xmlrpc_null_extension':
+ case 'xmlrpc_return_datetimes':
+ $this->current_parsing_options[$key] = $val;
+ break;
+
default:
$this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ": unsupported option: $key");
}
}
}
+ if (!isset($this->current_parsing_options['xmlrpc_null_extension'])) {
+ $this->current_parsing_options['xmlrpc_null_extension'] = PhpXmlRpc::$xmlrpc_null_extension;
+ }
+ if (!isset($this->current_parsing_options['xmlrpc_return_datetimes'])) {
+ $this->current_parsing_options['xmlrpc_return_datetimes'] = PhpXmlRpc::$xmlrpc_return_datetimes;
+ }
+
// NB: we use '' instead of null to force charset detection from the xml declaration
$parser = xml_parser_create('');
*/
public function xmlrpc_se($parser, $name, $attrs, $acceptSingleVals = false)
{
- // if invalid xmlrpc already detected, skip all processing
+ // if invalid xml-rpc already detected, skip all processing
if ($this->_xh['isf'] >= 2) {
return;
}
case 'NIL':
case 'EX:NIL':
- if (PhpXmlRpc::$xmlrpc_null_extension) {
+ if ($this->current_parsing_options['xmlrpc_null_extension']) {
if ($this->_xh['vt'] != 'value') {
// two data elements inside a value: an error occurred!
$this->_xh['isf'] = 2;
/**
* xml parser handler function for opening element tags.
- * Used in decoding xml chunks that might represent single xmlrpc values as well as requests, responses.
+ * Used in decoding xml chunks that might represent single xml-rpc values as well as requests, responses.
* @deprecated
*
* @param resource $parser
}
if ($rebuildXmlrpcvals > 0) {
- // build the xmlrpc val out of the data received, and substitute it
+ // build the xml-rpc val out of the data received, and substitute it
$temp = new Value($this->_xh['value'], $this->_xh['vt']);
// in case we got info about underlying php class, save it in the object we're rebuilding
if (isset($this->_xh['php_class'])) {
$this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid value received in DATETIME: ' . $this->_xh['ac']);
}
$this->_xh['vt'] = Value::$xmlrpcDateTime;
- $this->_xh['value'] = $this->_xh['ac'];
+ if ($this->current_parsing_options['xmlrpc_return_datetimes']) {
+ $this->_xh['value'] = new \DateTime($this->_xh['ac']);
+ } else {
+ $this->_xh['value'] = $this->_xh['ac'];
+ }
} elseif ($name == 'BASE64') {
/// @todo check for failure of base64 decoding / catch warnings
$this->_xh['value'] = base64_decode($this->_xh['ac']);
case 'NIL':
case 'EX:NIL':
- if (PhpXmlRpc::$xmlrpc_null_extension) {
+ if ($this->current_parsing_options['xmlrpc_null_extension']) {
$this->_xh['vt'] = 'null';
$this->_xh['value'] = null;
$this->_xh['lv'] = 3;
}
/**
- * Used in decoding xmlrpc requests/responses without rebuilding xmlrpc Values.
+ * Used in decoding xml-rpc requests/responses without rebuilding xml-rpc Values.
* @internal
*
* @param resource $parser
}
/**
- * Used in decoding xmlrpc requests/responses while building xmlrpc-extension Values (plain php for all but base64 and datetime).
+ * Used in decoding xml-rpc requests/responses while building xmlrpc-extension Values (plain php for all but base64 and datetime).
* @internal
*
* @param resource $parser
* The encoding used internally by PHP.
* String values received as xml will be converted to this, and php strings will be converted to xml as if
* having been coded with this.
- * Valid also when defining names of xmlrpc methods
+ * Valid also when defining names of xml-rpc methods
*/
public static $xmlrpc_internalencoding = "UTF-8";
*/
public static $xmlrpc_null_extension = false;
+ /**
+ * @var bool
+ * Set to TRUE to make the library use DateTime objects instead of strings for all values parsed from incoming XML
+ */
+ public static $xmlrpc_return_datetimes = false;
+
/**
* @var bool
* Set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
}
/**
- * Gets/sets the xmlrpc method to be invoked.
+ * Gets/sets the xml-rpc method to be invoked.
*
* @param string $methodName the method to be set (leave empty not to set it)
* @return string the method that will be invoked
*/
public function addParam($param)
{
- // check: do not add to self params which are not xmlrpc values
+ // check: do not add to self params which are not xml-rpc values
if (is_object($param) && is_a($param, 'PhpXmlRpc\Value')) {
$this->params[] = $param;
}
/**
- * Given an open file handle, read all data available and parse it as an xmlrpc response.
+ * Given an open file handle, read all data available and parse it as an xml-rpc response.
*
* NB: the file handle is not closed by this function.
* NNB: might have trouble in rare cases to work on network streams, as we check for a read of 0 bytes instead of
}
/**
- * Parse the xmlrpc response contained in the string $data and return a Response object.
+ * Parse the xml-rpc response contained in the string $data and return a Response object.
*
* When $this->debug has been set to a value greater than 0, will echo debug messages to screen while decoding.
*
- * @param string $data the xmlrpc response, possibly including http headers
+ * @param string $data the xml-rpc response, possibly including http headers
* @param bool $headersProcessed when true prevents parsing HTTP headers for interpretation of content-encoding and
* consequent decoding
* @param string $returnType decides return type, i.e. content of response->value(). Either 'xmlrpcvals', 'xml' or
}
/**
- * Enables/disables the echoing to screen of the xmlrpc responses received.
+ * Enables/disables the echoing to screen of the xml-rpc responses received.
*
* @param integer $level values 0, 1, 2 are supported
* @return $this
}
/**
- * @param Value|string|mixed $val either a Value object, a php value or the xml serialization of an xmlrpc value (a string)
+ * @param Value|string|mixed $val either a Value object, a php value or the xml serialization of an xml-rpc value (a string)
* @param integer $fCode set it to anything but 0 to create an error response. In that case, $val is discarded
* @param string $fString the error string, in case of an error response
* @param string $valType The type of $val passed in. Either 'xmlrpcvals', 'phpvals' or 'xml'. Leave empty to let
* @param array|null $httpResponse
*
* @todo add check that $val / $fCode / $fString is of correct type???
- * NB: as of now we do not do it, since it might be either an xmlrpc value or a plain php val, or a complete
+ * NB: as of now we do not do it, since it might be either an xml-rpc value or a plain php val, or a complete
* xml chunk, depending on usage of Client::send() inside which creator is called...
*/
public function __construct($val, $fCode = 0, $fString = '', $valType = '', $httpResponse = null)
/**
* @var int
* 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' xmlrpc response (default)
- * 1 = SECURITY SENSITIVE DO NOT ENABLE ON PUBLIC SERVERS!!! catch it and return an xmlrpc response with the error
+ * 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
*/
public $user_data = null;
/**
- * Array defining php functions exposed as xmlrpc methods by this server.
+ * Array defining php functions exposed as xml-rpc methods by this server.
* @var array[] $dmap
*/
protected $dmap = array();
/**
* Set debug level of server.
*
- * @param integer $level debug lvl: determines info added to xmlrpc responses (as xml comments)
+ * @param integer $level 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 xmlrpc request (headers and body),
+ * 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 an USER_ERROR level error will not halt script
- * execution anymore, but just end up logged in the xmlrpc response)
+ * 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 $this
*/
}
/**
- * Execute the xmlrpc request, printing the response.
+ * Execute the xml-rpc request, printing the response.
*
* @param string $data the request body. If null, the http POST request will be examined
* @param bool $returnPayload When true, return the response but do not echo it or any http header
/**
* Verify type and number of parameters received against a list of known signatures.
*
- * @param array|Request $in array of either xmlrpc value objects or xmlrpc type definitions
+ * @param array|Request $in array of either xml-rpc value objects or xml-rpc type definitions
* @param array $sigs array of known signatures to match against
* @return array int, string
*/
}
/**
- * Parse http headers received along with xmlrpc request. If needed, inflate request.
+ * Parse http headers received along with xml-rpc request. If needed, inflate request.
*
* @return Response|null null on success or an error Response
*/
PhpXmlRpc::$xmlrpcstr['invalid_request'] . ' ' . $xmlRpcParser->_xh['isf_reason']);
} else {
// small layering violation in favor of speed and memory usage: we should allow the 'execute' method handle
- // this, but in the most common scenario (xmlrpc values type server with some methods registered as phpvals)
+ // this, but in the most common scenario (xml-rpc values type server with some methods registered as phpvals)
// that would mean a useless encode+decode pass
if ($this->functions_parameters_type != 'xmlrpcvals' ||
(isset($this->dmap[$xmlRpcParser->_xh['method']]['parameters_type']) &&
*
* @param Request|string $req either a Request obj or a method name
* @param mixed[] $params array with method parameters as php types (only if $req is method name)
- * @param string[] $paramTypes array with xmlrpc types of method parameters (only if $req is method name)
+ * @param string[] $paramTypes array with xml-rpc types of method parameters (only if $req is method name)
* @return Response
*
* @throws \Exception in case the executed method does throw an exception (and depending on server configuration)
public function getCapabilities()
{
$outAr = array(
- // xmlrpc spec: always supported
+ // xml-rpc spec: always supported
'xmlrpc' => array(
- 'specUrl' => 'http://www.xmlrpc.com/spec',
+ 'specUrl' => 'http://www.xmlrpc.com/spec', // NB: the spec sits now at http://xmlrpc.com/spec.md
'specVersion' => 1
),
// if we support system.xxx functions, we always support multicall, too...
*/
public static function _xmlrpcs_methodSignature($server, $req)
{
- // let's accept as parameter either an xmlrpc value or string
+ // let's accept as parameter either an xml-rpc value or string
if (is_object($req)) {
$methName = $req->getParam(0);
$methName = $methName->scalarval();
*/
public static function _xmlrpcs_methodHelp($server, $req)
{
- // let's accept as parameter either an xmlrpc value or string
+ // let's accept as parameter either an xml-rpc value or string
if (is_object($req)) {
$methName = $req->getParam(0);
$methName = $methName->scalarval();
public static function _xmlrpcs_multicall($server, $req)
{
$result = array();
- // let accept a plain list of php parameters, beside a single xmlrpc msg object
+ // let accept a plain list of php parameters, beside a single xml-rpc msg object
if (is_object($req)) {
$calls = $req->getParam(0);
foreach ($calls as $call) {
/**
* Error handler used to track errors that occur during server-side execution of PHP code.
* This allows to report back to the client whether an internal error has occurred or not
- * using an xmlrpc response object, instead of letting the client deal with the html junk
+ * using an xml-rpc response object, instead of letting the client deal with the html junk
* that a PHP execution error on the server generally entails.
*
* NB: in fact a user defined error handler can only handle WARNING, NOTICE and USER_* errors.
}
/**
- * Build an xmlrpc value.
+ * Build an xml-rpc value.
*
* When no value or type is passed in, the value is left uninitialized, and the value can be added later.
*
* @param Value[]|mixed $val if passing in an array, all array elements should be PhpXmlRpc\Value themselves
- * @param string $type any valid xmlrpc type name (lowercase): i4, int, boolean, string, double, dateTime.iso8601,
+ * @param string $type any valid xml-rpc type name (lowercase): i4, int, boolean, string, double, dateTime.iso8601,
* base64, array, struct, null.
* If null, 'string' is assumed.
- * You should refer to http://www.xmlrpc.com/spec for more information on what each of these mean.
+ * You should refer to http://xmlrpc.com/spec.md for more information on what each of these mean.
*/
public function __construct($val = -1, $type = '')
{
}
/**
- * Add a single php value to an xmlrpc value.
+ * Add a single php value to an xml-rpc value.
*
- * If the xmlrpc value is an array, the php value is added as its last element.
- * If the xmlrpc value is empty (uninitialized), this method makes it a scalar value, and sets that value.
- * Fails if the xmlrpc value is not an array (i.e. a struct or a scalar) and already initialized.
+ * If the xml-rpc value is an array, the php value is added as its last element.
+ * If the xml-rpc value is empty (uninitialized), this method makes it a scalar value, and sets that value.
+ * Fails if the xml-rpc value is not an array (i.e. a struct or a scalar) and already initialized.
*
* @param mixed $val
* @param string $type allowed values: i4, i8, int, boolean, string, double, dateTime.iso8601, base64, null.
}
/**
- * Add an array of xmlrpc value objects to an xmlrpc value.
+ * Add an array of xml-rpc value objects to an xml-rpc value.
*
- * If the xmlrpc value is an array, the elements are appended to the existing ones.
- * If the xmlrpc value is empty (uninitialized), this method makes it an array value, and sets that value.
+ * If the xml-rpc value is an array, the elements are appended to the existing ones.
+ * If the xml-rpc value is empty (uninitialized), this method makes it an array value, and sets that value.
* Fails otherwise.
*
* @param Value[] $values
* @return int 1 or 0 on failure
*
- * @todo add some checking for $values to be an array of xmlrpc values?
+ * @todo add some checking for $values to be an array of xml-rpc values?
*/
public function addArray($values)
{
}
/**
- * Merges an array of named xmlrpc value objects into an xmlrpc value.
+ * Merges an array of named xml-rpc value objects into an xml-rpc value.
*
- * If the xmlrpc value is a struct, the elements are merged with the existing ones (overwriting existing ones).
- * If the xmlrpc value is empty (uninitialized), this method makes it a struct value, and sets that value.
+ * If the xml-rpc value is a struct, the elements are merged with the existing ones (overwriting existing ones).
+ * If the xml-rpc value is empty (uninitialized), this method makes it a struct value, and sets that value.
* Fails otherwise.
*
* @param Value[] $values
break;
case static::$xmlrpcDouble:
// avoid using standard conversion of float to string because it is locale-dependent,
- // and also because the xmlrpc spec forbids exponential notation.
+ // and also because the xml-rpc spec forbids exponential notation.
// sprintf('%F') could be most likely ok, but it fails e.g. on 2e-14.
// The code below tries its best at keeping max precision while avoiding exp notation,
// but there is of course no limit in the number of decimal places to be used...
break;
default:
// no standard type value should arrive here, but provide a possibility
- // for xmlrpc values of unknown type...
+ // for xml-rpc values of unknown type...
$rs .= "<{$typ}>{$val}</{$typ}>";
}
break;
/**
* Checks whether a struct member with a given name is present.
*
- * Works only on xmlrpc values of type struct.
+ * Works only on xml-rpc values of type struct.
*
* @param string $key the name of the struct member to be looked up
* @return boolean
}
/**
- * Returns the value of a given struct member (an xmlrpc value object in itself).
+ * Returns the value of a given struct member (an xml-rpc value object in itself).
* Will raise a php warning if struct member of given name does not exist.
*
* @param string $key the name of the struct member to be looked up
}
/**
- * Reset internal pointer for xmlrpc values of type struct.
+ * Reset internal pointer for xml-rpc values of type struct.
* @return void
*
* @deprecated iterate directly over the object using foreach instead
}
/**
- * Return next member element for xmlrpc values of type struct.
+ * Return next member element for xml-rpc values of type struct.
*
* @return Value
* @throws \Error starting with php 8.0, this function should not be used, as it will always throw
}
/**
- * Returns the value of a scalar xmlrpc value (base 64 decoding is automatically handled here)
+ * Returns the value of a scalar xml-rpc value (base 64 decoding is automatically handled here)
*
* @return mixed
*/
}
/**
- * Returns the type of the xmlrpc value.
+ * Returns the type of the xml-rpc value.
*
* For integers, 'int' is always returned in place of 'i4'. 'i8' is considered a separate type and returned as such
*
}
/**
- * Returns the m-th member of an xmlrpc value of array type.
+ * Returns the m-th member of an xml-rpc value of array type.
*
* @param integer $key the index of the value to be retrieved (zero based)
*
}
/**
- * Returns the number of members in an xmlrpc value of array type.
+ * Returns the number of members in an xml-rpc value of array type.
*
* @return integer
*
}
/**
- * Returns the number of members in an xmlrpc value of struct type.
+ * Returns the number of members in an xml-rpc value of struct type.
*
* @return integer
*
}
/**
- * Returns the number of members in an xmlrpc value:
+ * Returns the number of members in an xml-rpc value:
* - 0 for uninitialized values
* - 1 for scalar values
* - the number of elements for struct and array values
use PhpXmlRpc\Helper\Logger;
/**
- * PHPXMLRPC "wrapper" class - generate stubs to transparently access xmlrpc methods as php functions and vice-versa.
+ * PHPXMLRPC "wrapper" class - generate stubs to transparently access xml-rpc methods as php functions and vice-versa.
* Note: this class implements the PROXY pattern, but it is not named so to avoid confusion with http proxies.
*
* @todo use some better templating system for code generation?
* accepted come from javadoc blocks), return corresponding phpxmlrpc type.
* Notes:
* - for php 'resource' types returns empty string, since resources cannot be serialized;
- * - for php class names returns 'struct', since php objects can be serialized as xmlrpc structs
+ * - for php class names returns 'struct', since php objects can be serialized as xml-rpc structs
* - for php arrays always return array, even though arrays sometimes serialize as structs...
* - for 'void' and 'null' returns 'undefined'
*
}
return Value::$xmlrpcStruct;
} else {
- // unknown: might be any 'extended' xmlrpc type
+ // unknown: might be any 'extended' xml-rpc type
return Value::$xmlrpcValue;
}
}
case 'boolean':
case 'null':
default:
- // unknown: might be any xmlrpc type
+ // unknown: might be any xml-rpc type
return strtolower($xmlrpcType);
}
}
/**
- * Given a user-defined PHP function, create a PHP 'wrapper' function that can be exposed as xmlrpc method from an
- * xmlrpc server object and called from remote clients (as well as its corresponding signature info).
+ * Given a user-defined PHP function, create a PHP 'wrapper' function that can be exposed as xml-rpc method from an
+ * xml-rpc server object and called from remote clients (as well as its corresponding signature info).
*
* Since php is a typeless language, to infer types of input and output parameters, it relies on parsing the
- * javadoc-style comment block associated with the given function. Usage of xmlrpc native types (such as
+ * javadoc-style comment block associated with the given function. Usage of xml-rpc native types (such as
* datetime.dateTime.iso8601 and base64) in the '@param' tag is also allowed, if you need the php function to
* receive/send data in that particular format (note that base64 encoding/decoding is transparently carried out by
* the lib, while datetime values are passed around as strings)
* Known limitations:
* - only works for user-defined functions, not for PHP internal functions (reflection does not support retrieving
* number/type of params for those)
- * - functions returning php objects will generate special structs in xmlrpc responses: when the xmlrpc decoding of
+ * - functions returning php objects will generate special structs in xml-rpc responses: when the xml-rpc decoding of
* those responses is carried out by this same lib, using the appropriate param in php_xmlrpc_decode, the php
* objects will be rebuilt.
* In short: php objects can be serialized, too (except for their resource members), using this function.
* not expecting a single Request obj as parameter) is by making use of the $functions_parameters_type and
* $exception_handling properties.
*
- * @param \Callable $callable the PHP user function to be exposed as xmlrpc method: a closure, function name, array($obj, 'methodname') or array('class', 'methodname') are ok
+ * @param \Callable $callable the PHP user function to be exposed as xml-rpc method: a closure, function name, array($obj, 'methodname') or array('class', 'methodname') are ok
* @param string $newFuncName (optional) name for function to be created. Used only when return_source in $extraOptions is true
* @param array $extraOptions (optional) array of options for conversion. valid values include:
* - bool return_source when true, php code w. function definition will be returned, instead of a closure
- * - bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
+ * - bool encode_php_objs let php objects be sent to server using the 'improved' xml-rpc notation, so server can deserialize them as php objects
* - bool decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
* - bool suppress_warnings remove from produced xml any warnings generated at runtime by the php function being invoked
* @return array|false false on error, or an array containing the name of the new php function,
/**
* Return a name for a new function, based on $callable, insuring its uniqueness
- * @param mixed $callable a php callable, or the name of an xmlrpc method
+ * @param mixed $callable a php callable, or the name of an xml-rpc method
* @param string $newFuncName when not empty, it is used instead of the calculated version
* @return string
*/
/**
* Given a user-defined PHP class or php object, map its methods onto a list of
- * PHP 'wrapper' functions that can be exposed as xmlrpc methods from an xmlrpc server
+ * PHP 'wrapper' functions that can be exposed as xml-rpc methods from an xml-rpc server
* object and called from remote clients (as well as their corresponding signature info).
*
- * @param string|object $className the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class
+ * @param string|object $className the name of the class whose methods are to be exposed as xml-rpc methods, or an object instance of that class
* @param array $extraOptions see the docs for wrapPhpMethod for basic options, plus
* - string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on whether $className is a class name or object instance
* - string method_filter a regexp used to filter methods to wrap based on their names
- * - string prefix used for the names of the xmlrpc methods created.
+ * - string prefix used for the names of the xml-rpc methods created.
* - string replace_class_name use to completely replace the class name with the prefix in the generated method names. e.g. instead of \Some\Namespace\Class.method use prefixmethod
* @return array|false false on failure, or on array useable for the dispatch map
*/
}
/**
- * Given an xmlrpc client and a method name, register a php wrapper function that will call it and return results
+ * Given an xml-rpc client and a method name, register a php wrapper function that will call it and return results
* using native php types for both arguments and results. The generated php function will return a Response
- * object for failed xmlrpc calls.
+ * object for failed xml-rpc calls.
*
* Known limitations:
- * - server must support system.methodSignature for the target xmlrpc method
+ * - server must support system.methodSignature for the target xml-rpc method
* - for methods that expose many signatures, only one can be picked (we could in principle check if signatures
* differ only by number of params and not by type, but it would be more complication than we can spare time for)
- * - nested xmlrpc params: the caller of the generated php function has to encode on its own the params passed to
+ * - nested xml-rpc params: the caller of the generated php function has to encode on its own the params passed to
* the php function if these are structs or arrays whose (sub)members include values of type base64
*
* Notes: the connection properties of the given client will be copied and reused for the connection used during
* the call to the generated php function.
- * Calling the generated php function 'might' be slightly slow: a new xmlrpc client is created on every invocation
+ * Calling the generated php function 'might' be slightly slow: a new xml-rpc client is created on every invocation
* and an xmlrpc-connection opened+closed.
* An extra 'debug' argument, defaulting to 0, is appended to the argument list of the generated function, useful
* for debugging purposes.
*
- * @param Client $client an xmlrpc client set up correctly to communicate with target server
- * @param string $methodName the xmlrpc method to be mapped to a php function
+ * @param Client $client an xml-rpc client set up correctly to communicate with target server
+ * @param string $methodName the xml-rpc method to be mapped to a php function
* @param array $extraOptions array of options that specify conversion details. Valid options include
* - integer signum the index of the method signature to use in mapping (if method exposes many sigs)
* - integer timeout timeout (in secs) to be used when executing function/calling remote method
* - string protocol 'http' (default), 'http11', 'https', 'h2' or 'h2c'
* - string new_function_name the name of php function to create, when return_source is used. If unspecified, lib will pick an appropriate name
* - string return_source if true return php code w. function definition instead of function itself (closure)
- * - bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects
+ * - bool encode_php_objs let php objects be sent to server using the 'improved' xml-rpc notation, so server can deserialize them as php objects
* - bool decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers ---
- * - mixed return_on_fault a php value to be returned when the xmlrpc call fails/returns a fault response (by default the Response object is returned in this case). If a string is used, '%faultCode%' and '%faultString%' tokens will be substituted with actual error values
+ * - mixed return_on_fault a php value to be returned when the xml-rpc call fails/returns a fault response (by default the Response object is returned in this case). If a string is used, '%faultCode%' and '%faultString%' tokens will be substituted with actual error values
* - bool throw_on_fault if true, throw an exception instead of returning a Response in case of errors/faults;
* if a string, do the same and assume it is the exception class to throw
* - bool debug set it to 1 or 2 to see debug results of querying server for method synopsis
}
/**
- * Retrieves an xmlrpc method signature from a server which supports system.methodSignature
+ * Retrieves an xml-rpc method signature from a server which supports system.methodSignature
* @param Client $client
* @param string $methodName
* @param array $extraOptions
if ($pType == 'i4' || $pType == 'i8' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' ||
$pType == 'string' || $pType == 'dateTime.iso8601' || $pType == 'base64' || $pType == 'null'
) {
- // by building directly xmlrpc values when type is known and scalar (instead of encode() calls),
- // we make sure to honour the xmlrpc signature
+ // by building directly xml-rpc values when type is known and scalar (instead of encode() calls),
+ // we make sure to honour the xml-rpc signature
$xmlrpcArgs[] = new $valueClass($arg, $pType);
} else {
$xmlrpcArgs[] = $encoder->encode($arg, $encodeOptions);
if ($pType == 'i4' || $pType == 'i8' || $pType == 'int' || $pType == 'boolean' || $pType == 'double' ||
$pType == 'string' || $pType == 'dateTime.iso8601' || $pType == 'base64' || $pType == 'null'
) {
- // only build directly xmlrpc values when type is known and scalar
+ // only build directly xml-rpc values when type is known and scalar
$innerCode .= " \$p$i = new " . static::$namespace . "Value(\$p$i, '$pType');\n";
} else {
if ($encodePhpObjects) {
}
/**
- * Similar to wrapXmlrpcMethod, but will generate a php class that wraps all xmlrpc methods exposed by the remote
+ * Similar to wrapXmlrpcMethod, but will generate a php class that wraps all xml-rpc methods exposed by the remote
* server as own methods.
* For a slimmer alternative, see the code in demo/client/proxy.php.
* Note that unlike wrapXmlrpcMethod, we always have to generate php code here. Since php 7 anon classes exist, but