15 function __construct( $data, $type = false )
19 $type = $this->calculateType();
22 if ($type == 'struct') {
23 // Turn all the values in the array in to new IXR_Value objects
24 foreach ($this->data as $key => $value) {
25 $this->data[$key] = new IXR_Value($value);
28 if ($type == 'array') {
29 for ($i = 0, $j = count($this->data); $i < $j; $i++) {
30 $this->data[$i] = new IXR_Value($this->data[$i]);
38 public function IXR_Value( $data, $type = false ) {
39 self::__construct( $data, $type );
42 function calculateType()
44 if ($this->data === true || $this->data === false) {
47 if (is_integer($this->data)) {
50 if (is_double($this->data)) {
54 // Deal with IXR object types base64 and date
55 if (is_object($this->data) && is_a($this->data, 'IXR_Date')) {
58 if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) {
62 // If it is a normal PHP object convert it in to a struct
63 if (is_object($this->data)) {
64 $this->data = get_object_vars($this->data);
67 if (!is_array($this->data)) {
71 // We have an array - is it an array or a struct?
72 if ($this->isStruct($this->data)) {
81 // Return XML for this value
82 switch ($this->type) {
84 return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
87 return '<int>'.$this->data.'</int>';
90 return '<double>'.$this->data.'</double>';
93 return '<string>'.htmlspecialchars($this->data).'</string>';
96 $return = '<array><data>'."\n";
97 foreach ($this->data as $item) {
98 $return .= ' <value>'.$item->getXml()."</value>\n";
100 $return .= '</data></array>';
104 $return = '<struct>'."\n";
105 foreach ($this->data as $name => $value) {
106 $name = htmlspecialchars($name);
107 $return .= " <member><name>$name</name><value>";
108 $return .= $value->getXml()."</value></member>\n";
110 $return .= '</struct>';
115 return $this->data->getXml();
122 * Checks whether or not the supplied array is a struct or not
124 * @param array $array
127 function isStruct($array)
130 foreach ($array as $key => $value) {
131 if ((string)$key !== (string)$expected) {