NXS_XMLRPC_Value

IXR - The Incutio XML-RPC Library.

Defined (1)

The class is defined in the following location(s).

/inc-cl/apis/xmlrpc-client.php  
  1. class NXS_XMLRPC_Value 
  2. var $data; 
  3. var $type; 
  4.  
  5. function NXS_XMLRPC_Value($data, $type = false) 
  6. $this->data = $data; 
  7. if (!$type) { 
  8. $type = $this->calculateType(); 
  9. $this->type = $type; 
  10. if ($type == 'struct') { 
  11. // Turn all the values in the array in to new NXS_XMLRPC_Value objects 
  12. foreach ($this->data as $key => $value) { 
  13. $this->data[$key] = new NXS_XMLRPC_Value($value); 
  14. if ($type == 'array') { 
  15. for ($i = 0, $j = count($this->data); $i < $j; $i++) { 
  16. $this->data[$i] = new NXS_XMLRPC_Value($this->data[$i]); 
  17.  
  18. function calculateType() 
  19. if ($this->data === true || $this->data === false) { 
  20. return 'boolean'; 
  21. if (is_integer($this->data)) { 
  22. return 'int'; 
  23. if (is_double($this->data)) { 
  24. return 'double'; 
  25.  
  26. // Deal with IXR object types base64 and date 
  27. if (is_object($this->data) && is_a($this->data, 'NXS_XMLRPC_Date')) { 
  28. return 'date'; 
  29. if (is_object($this->data) && is_a($this->data, 'NXS_XMLRPC_Base64')) { 
  30. return 'base64'; 
  31.  
  32. // If it is a normal PHP object convert it in to a struct 
  33. if (is_object($this->data)) { 
  34. $this->data = get_object_vars($this->data); 
  35. return 'struct'; 
  36. if (!is_array($this->data)) { 
  37. return 'string'; 
  38.  
  39. // We have an array - is it an array or a struct? 
  40. if ($this->isStruct($this->data)) { 
  41. return 'struct'; 
  42. } else { 
  43. return 'array'; 
  44.  
  45. function getXml() 
  46. // Return XML for this value 
  47. switch ($this->type) { 
  48. case 'boolean': 
  49. return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; 
  50. break; 
  51. case 'int': 
  52. return '<int>'.$this->data.'</int>'; 
  53. break; 
  54. case 'double': 
  55. return '<double>'.$this->data.'</double>'; 
  56. break; 
  57. case 'string': 
  58. return '<string>'.htmlspecialchars($this->data).'</string>'; 
  59. break; 
  60. case 'array': 
  61. $return = '<array><data>'."\n"; 
  62. foreach ($this->data as $item) { 
  63. $return .= ' <value>'.$item->getXml()."</value>\n"; 
  64. $return .= '</data></array>'; 
  65. return $return; 
  66. break; 
  67. case 'struct': 
  68. $return = '<struct>'."\n"; 
  69. foreach ($this->data as $name => $value) { 
  70. $return .= " <member><name>$name</name><value>"; 
  71. $return .= $value->getXml()."</value></member>\n"; 
  72. $return .= '</struct>'; 
  73. return $return; 
  74. break; 
  75. case 'date': 
  76. case 'base64': 
  77. return $this->data->getXml(); 
  78. break; 
  79. return false; 
  80.  
  81. /** 
  82. * Checks whether or not the supplied array is a struct or not 
  83. * @param unknown_type $array 
  84. * @return boolean 
  85. */ 
  86. function isStruct($array) 
  87. $expected = 0; 
  88. foreach ($array as $key => $value) { 
  89. if ((string)$key != (string)$expected) { 
  90. return true; 
  91. $expected++; 
  92. return false;