news
authorgggeek <giunta.gaetano@gmail.com>
Mon, 23 Jan 2023 09:23:55 +0000 (09:23 +0000)
committergggeek <giunta.gaetano@gmail.com>
Mon, 23 Jan 2023 09:23:55 +0000 (09:23 +0000)
NEWS.md
demo/client/codegen.php
demo/server/codegen.php
doc/manual/phpxmlrpc_manual.adoc
src/Encoder.php
src/PhpXmlRpc.php

diff --git a/NEWS.md b/NEWS.md
index 02d949e..7c833f6 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -37,6 +37,8 @@
   a method handler in the dispatch was defined with `'parameters_type' = 'phpvals'`, the handler would be passed a
   Request object instead of plain php values.
 
+* fixed: receiving integers which use the '<EX:I8>' xml tag
+
 * new: added the `Client::setTimeout` method, meant to replace usage of the `$timeout` argument in calls to `send`
   and `multicall`
 
index 672bfa1..d4842bc 100644 (file)
@@ -19,6 +19,7 @@ $code = $w->wrapXmlrpcServer(
         'new_class_name' => 'MyClient',
         'method_filter' => '/^examples\./',
         'simple_client_copy' => true,
+        // this is used to encode php NULL values into xml-rpc <NIL/> elements. If the partner does not support that, disable it
         'encode_nulls' => true,
         'throw_on_fault' => true,
     )
index db06d15..c76d301 100644 (file)
@@ -13,6 +13,7 @@ $code = $w->wrapPhpClass(
     array(
         'method_type' => 'nonstatic',
         'return_source' => true,
+        // this is used to encode php NULL values into xml-rpc <NIL/> elements. If the partner does not support that, disable it
         'encode_nulls' => true,
     )
 );
index 20bb60f..1e6ed30 100644 (file)
@@ -251,6 +251,16 @@ for `PhpXmlRpc\Encoder::decode` for the full details of the decoding process.
 
 ==== Notes on types
 
+==== strict parsing vs. lenient parsing
+
+When Value objects are created by the library by parsing some received XML text, the parsing code is lenient with invalid
+data. This means that if the other party is sending some junk, the library will, by default:
+- log error messages pinpointing the exact source of the problem, and
+- feed to your application "error values", which include `false` for bad base64 data, the string 'ERROR_NON_NUMERIC_FOUND'
+  for integers and doubles, `false` for invalid booleans and the received string for invalid datetimes.
+This behaviour can be changed to make the parsing code more strict and produce an error instead of letting through invalid
+data, by setting `PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true`.
+
 ===== base64
 
 Base 64 encoding is performed transparently to the caller when using this type. Decoding is also transparent.
@@ -259,12 +269,13 @@ Therefore, you ought to consider it as a "binary" data type, for use when you wa
 ===== boolean
 
 All php values which would be converted to a boolean TRUE via typecasting are mapped to an xml-rpc `true`. All other
-values (including the empty string) are converted to `false`.
+values (including the empty string) are converted to an xml-rpc `false`.
 
-===== dateTime
+===== dateTime.iso8601
 
-When manually creating Value objects representing an xml-rpc dateTime.iso8601, php integers, strings and DateTimes can be
-used as source values. For those, the original value will be returned when calling `+$value->scalarval();+`.
+When manually creating Value objects representing an xml-rpc dateTime.iso8601, php DateTimes, integers (unix timestamps)
+and strings (representing dates in the specific xml-rpc ISO-8601 format) can be 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 by default return the string representation of the date when calling `+$value->scalarval();+`.
@@ -274,10 +285,14 @@ of timezone specifiers in ISO8601 format dates. You can, however, use multiple t
 into another representation of a time stamp, and take care of timezones by yourself:
 * use the `PhpXmlRpc\Helper\Date` class to convert 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).
+  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 from a
-  single Value object (in which case the conversion is done using the `strtotime` function, which uses the timezone set
-  in php.ini).
+  single or nested Value object (in which case the conversion is done using the `strtotime` function, which uses the
+  timezone set in php.ini).
+Note that, when using `$xmlrpc_return_datetimes` or 'dates_as_objects', you might still get back a php `false` or `null`
+instead of a DateTime if the data received via xml does not represent a valid date and time. You can configure the library
+to outright reject such cases and avoid having to explicitly check for them in your own code, by setting
+`PhpXmlRpc\PhpXmlRpc::$xmlrpc_return_datetimes = true`.
 
 ===== double
 
index 7227700..03fabed 100644 (file)
@@ -118,11 +118,14 @@ class Encoder
                     }
                 }
                 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 xml-rpc 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)) {
                         $out = strtotime($out);
+                        // NB: if the string does not convert into a timestamp, this will return false.
+                        // We avoid logging an error here, as we presume it was already done when parsing the xml
+                        /// @todo we could return null, to be more in line with what the XMLParser does...
                     }
                     if (is_int($out)) {
                         $result = new \DateTime();
index c6c01b3..4c3a80f 100644 (file)
@@ -138,7 +138,8 @@ class PhpXmlRpc
     /**
      * @var bool
      * Set to TRUE to make the library use DateTime objects instead of strings for all values parsed from incoming XML.
-     * NB: if the received strings are not parseable as dates, NULL will be returned!
+     * NB: if the received strings are not parseable as dates, NULL will be returned. To prevent that, enable as
+     * well `xmlrpc_reject_invalid_values`, so that invalid dates will be rejected by the library
      */
     public static $xmlrpc_return_datetimes = false;
 
@@ -146,7 +147,7 @@ class PhpXmlRpc
      * @var bool
      * Set to TRUE to make the library reject incoming xml which uses invalid data from xml-rpc Value elements, such
      * as base64 strings which can not be decoded, dateTime strings which do not represent a valid date, invalid bools,
-     * floats and inteers
+     * floats and integers
      */
     public static $xmlrpc_reject_invalid_values = false;