Less specific date type detection
[plcapi.git] / src / Value.php
index c9fc614..97852b0 100644 (file)
@@ -5,11 +5,12 @@ namespace PhpXmlRpc;
 use PhpXmlRpc\Helper\Charset;
 
 /**
- * This class enables the creation and encapsulation of values for XML-RPC.
+ * This class enables the creation of values for XML-RPC, by encapsulating plain php values.
  */
 class Value implements \Countable, \IteratorAggregate, \ArrayAccess
 {
     public static $xmlrpcI4 = "i4";
+    public static $xmlrpcI8 = "i8";
     public static $xmlrpcInt = "int";
     public static $xmlrpcBoolean = "boolean";
     public static $xmlrpcDouble = "double";
@@ -23,6 +24,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
 
     public static $xmlrpcTypes = array(
         "i4" => 1,
+        "i8" => 1,
         "int" => 1,
         "boolean" => 1,
         "double" => 1,
@@ -61,6 +63,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
                     $this->me['string'] = $val;
                     break;
                 case 'i4':
+                case 'i8':
                 case 'int':
                 case 'double':
                 case 'string':
@@ -93,7 +96,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
      * Fails if the xmlrpc value is not an array and already initialized.
      *
      * @param mixed $val
-     * @param string $type allowed values: i4, int, boolean, string, double, dateTime.iso8601, base64, null.
+     * @param string $type allowed values: i4, i8, int, boolean, string, double, dateTime.iso8601, base64, null.
      *
      * @return int 1 or 0 on failure
      */
@@ -110,7 +113,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
         }
 
         // coerce booleans into correct values
-        // NB: we should either do it for datetimes, integers and doubles, too,
+        // NB: we should either do it for datetimes, integers, i8 and doubles, too,
         // or just plain remove this check, implemented on booleans only...
         if ($type == static::$xmlrpcBoolean) {
             if (strcasecmp($val, 'true') == 0 || $val == 1 || ($val == true && strcasecmp($val, 'false'))) {
@@ -249,6 +252,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
                         break;
                     case static::$xmlrpcInt:
                     case static::$xmlrpcI4:
+                    case static::$xmlrpcI8:
                         $rs .= "<${typ}>" . (int)$val . "</${typ}>";
                         break;
                     case static::$xmlrpcDouble:
@@ -325,14 +329,10 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
      */
     public function serialize($charsetEncoding = '')
     {
-        // add check? slower, but helps to avoid recursion in serializing broken xmlrpc values...
-        //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))
-        //{
         reset($this->me);
         list($typ, $val) = each($this->me);
 
         return '<value>' . $this->serializedata($typ, $val, $charsetEncoding) . "</value>\n";
-        //}
     }
 
     /**
@@ -403,7 +403,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
     /**
      * Returns the type of the xmlrpc value.
      *
-     * For integers, 'int' is always returned in place of 'i4'.
+     * For integers, 'int' is always returned in place of 'i4'. 'i8' is considered a separate type and returned as such
      *
      * @return string
      */
@@ -497,7 +497,6 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
         return new \ArrayIterator();
     }
 
-
     public function offsetSet($offset, $value) {
 
         switch ($this->mytype) {
@@ -584,4 +583,4 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
                 throw new \Exception("XML-RPC Value is of type 'undef' and can not be accessed using array index");
         }
     }
-}
\ No newline at end of file
+}