ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
XML_RPC2_Backend_Php_Value Class Reference
+ Inheritance diagram for XML_RPC2_Backend_Php_Value:
+ Collaboration diagram for XML_RPC2_Backend_Php_Value:

Public Member Functions

 getNativeValue ()
 nativeValue property getter More...
 

Static Public Member Functions

static createFromNative ($nativeValue, $explicitType=null)
 Choose a XML_RPC2_Value subclass appropriate for the given value and create it. More...
 
static createFromDecode ($simpleXML)
 Decode an encoded value and build the applicable XML_RPC2_Value subclass. More...
 
- Static Public Member Functions inherited from XML_RPC2_Value
static createFromNative ($value, $explicitType=null)
 Factory method that constructs the appropriate XML-RPC encoded type value. More...
 

Protected Member Functions

 setNativeValue ($value)
 nativeValue setter More...
 

Private Attributes

 $_nativeValue = null
 

Detailed Description

Definition at line 57 of file Value.php.

Member Function Documentation

◆ createFromDecode()

static XML_RPC2_Backend_Php_Value::createFromDecode (   $simpleXML)
static

Decode an encoded value and build the applicable XML_RPC2_Value subclass.

Parameters
SimpleXMLElementThe encoded XML-RPC value
Returns
mixed the corresponding XML_RPC2_Value object

Definition at line 215 of file Value.php.

Referenced by XML_RPC2_Backend_Php_Request\createFromDecode(), XML_RPC2_FaultException\createFromDecode(), XML_RPC2_Backend_Php_Value_Array\decode(), XML_RPC2_Backend_Php_Value_Struct\decode(), and XML_RPC2_Backend_Php_Response\decode().

216  {
217  // TODO Remove reparsing of XML fragment, when SimpleXML proves more solid. Currently it segfaults when
218  // xpath is used both in an element and in one of its children
219  $simpleXML = simplexml_load_string($simpleXML->asXML());
220 
221  $valueType = $simpleXML->xpath('./*');
222  if (count($valueType) == 1) { // Usually we must check the node name
223  $nodename = dom_import_simplexml($valueType[0])->nodeName;
224  switch ($nodename) {
225  case 'i4':
226  case 'int':
227  $nativeType = 'Integer';
228  break;
229  case 'boolean':
230  $nativeType = 'Boolean';
231  break;
232  case 'double':
233  $nativeType = 'Double';
234  break;
235  case 'string':
236  $nativeType = 'String';
237  break;
238  case 'dateTime.iso8601':
239  $nativeType = 'Datetime';
240  break;
241  case 'base64':
242  $nativeType = 'Base64';
243  break;
244  case 'array':
245  $nativeType = 'Array';
246  break;
247  case 'struct':
248  $nativeType = 'Struct';
249  break;
250  default:
251  throw new XML_RPC2_DecodeException(sprintf('Unable to decode XML-RPC value. Value type is not recognized \'%s\'', $nodename));
252  }
253  } elseif (count($valueType) == 0) { // Default type is string
254  $nodename = null;
255  $nativeType = 'String';
256  } else {
257  throw new XML_RPC2_DecodeException(sprintf('Unable to decode XML-RPC value. Value presented %s type nodes: %s.', count($valueType), $simpleXML->asXML()));
258  }
259  require_once(sprintf('XML/RPC2/Backend/Php/Value/%s.php', $nativeType));
260  $nativeType = 'XML_RPC2_Backend_Php_Value_' . $nativeType;
261  return self::createFromNative(@call_user_func(array($nativeType, 'decode'), $simpleXML), $nodename);
262  }
+ Here is the caller graph for this function:

◆ createFromNative()

static XML_RPC2_Backend_Php_Value::createFromNative (   $nativeValue,
  $explicitType = null 
)
static

Choose a XML_RPC2_Value subclass appropriate for the given value and create it.

This method tries to find the most adequate XML-RPC datatype to hold a given PHP native type. Note that distinguishing some datatypes may be difficult:

  • Timestamps are represented by PHP integers, so an XML_RPC2_Value_Datetime is never returned
  • Indexed arrays and associative arrays are the same native PHP type. In this case: a) The array's indexes start at 0 or 1 and increase monotonically with step 1, or b) they do not in the first case, an XML_RPC2_Value_Array is returned. In the second, a XML_RPC2_Value_Struct is returned.
  • PHP Objects are serialized and represented in an XML_RPC2_Value_Base64

Whenever native object automatic detection proves inaccurate, use XML_RPC2_Value::createFromNative providing a valid explicit type as second argument

the appropriate XML_RPC2_Value child class instead.

Parameters
mixedThe native value
stringThe xml-rpc target encoding type, as per the xmlrpc spec (optional)
Exceptions
XML_RPC2_InvalidTypeEncodeExceptionWhen the native value has a type that can't be translated to XML_RPC
Returns
A new XML_RPC2_Value instance
See also
XML_RPC_Client::__call
XML_RPC_Server

Definition at line 123 of file Value.php.

References XML_RPC2_Backend_Php_Value_Scalar\createFromNative().

Referenced by XML_RPC2_Backend_Php_Response\encode(), XML_RPC2_Backend_Php_Value_Array\encode(), XML_RPC2_Backend_Php_Value_Struct\encode(), and XML_RPC2_Backend_Php_Request\encode().

124  {
125  if (is_null($explicitType)) {
126  switch (gettype($nativeValue)) {
127  case 'boolean':
128  $explicitType = 'boolean';
129  break;
130  case 'integer':
131  $explicitType = 'int';
132  break;
133  case 'double':
134  $explicitType = 'double';
135  break;
136  case 'string':
137  $explicitType = 'string';
138  break;
139  case 'array':
140  $explicitType = 'array';
141  $keys = array_keys($nativeValue);
142  if (count($keys) > 0) {
143  if ($keys[0] !== 0 && ($keys[0] !== 1)) $explicitType = 'struct';
144  $i=0;
145  do {
146  $previous = $keys[$i];
147  $i++;
148  if (array_key_exists($i, $keys) && ($keys[$i] !== $keys[$i - 1] + 1)) $explicitType = 'struct';
149  } while (array_key_exists($i, $keys) && $explicitType == 'array');
150  }
151  break;
152  case 'object':
153  if ((strtolower(get_class($nativeValue)) == 'stdclass') && (isset($nativeValue->xmlrpc_type))) {
154  // In this case, we have a "stdclass native value" (emulate xmlrpcext)
155  // the type 'base64' or 'datetime' is given by xmlrpc_type public property
156  $explicitType = $nativeValue->xmlrpc_type;
157  } else {
158  $nativeValue = serialize($nativeValue);
159  $explicitType = 'base64';
160  }
161  break;
162  case 'resource':
163  case 'NULL':
164  case 'unknown type':
165  throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Impossible to encode value \'%s\' from type \'%s\'. No analogous type in XML_RPC.',
166  (string) $nativeValue,
167  gettype($nativeValue)));
168  default:
169  throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Unexpected PHP native type returned by gettype: \'%s\', for value \'%s\'',
170  gettype($nativeValue),
171  (string) $nativeValue));
172  }
173  }
174  $explicitType = ucfirst(strtolower($explicitType));
175  switch ($explicitType) {
176  case 'I4':
177  case 'Int':
178  case 'Boolean':
179  case 'Double':
180  case 'String':
181  require_once 'XML/RPC2/Backend/Php/Value/Scalar.php';
183  break;
184  case 'Datetime.iso8601':
185  case 'Datetime':
186  require_once 'XML/RPC2/Backend/Php/Value/Datetime.php';
187  return new XML_RPC2_Backend_Php_Value_Datetime($nativeValue);
188  break;
189  case 'Base64':
190  require_once 'XML/RPC2/Backend/Php/Value/Base64.php';
191  return new XML_RPC2_Backend_Php_Value_Base64($nativeValue);
192  break;
193  case 'Array':
194  require_once 'XML/RPC2/Backend/Php/Value/Array.php';
195  return new XML_RPC2_Backend_Php_Value_Array($nativeValue);
196  break;
197  case 'Struct':
198  require_once 'XML/RPC2/Backend/Php/Value/Struct.php';
199  return new XML_RPC2_Backend_Php_Value_Struct($nativeValue);
200  break;
201  default:
202  throw new XML_RPC2_InvalidTypeEncodeException(sprintf('Unexpected explicit encoding type \'%s\'', $explicitType));
203  }
204  }
static createFromNative($nativeValue, $explicitType=null)
Choose a XML_RPC2_Value subclass appropriate for the given value and create it.
Definition: Scalar.php:133
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNativeValue()

XML_RPC2_Backend_Php_Value::getNativeValue ( )

◆ setNativeValue()

XML_RPC2_Backend_Php_Value::setNativeValue (   $value)
protected

Field Documentation

◆ $_nativeValue

XML_RPC2_Backend_Php_Value::$_nativeValue = null
private

Definition at line 66 of file Value.php.

Referenced by getNativeValue().


The documentation for this class was generated from the following file: