11 $this->Data = array();
12 $this->Warnings = array();
17 $this->Data[$Key] = $Value;
22 $this->Warnings[] = strval($Message);
27 $this->SendResult($this->GenerateResult(
"ERROR", $Message));
32 $this->SendResult($this->GenerateResult(
"OK", $Message));
35 private function SendResult(array $Result)
38 header(
"Content-Type: application/json; charset="
39 .$SysConfig->DefaultCharacterSet(), TRUE);
40 $this->PrintArrayToJson($Result);
43 private function GenerateResult($State, $Message)
46 "data" => $this->Data,
48 "state" => strval($State),
49 "message" => strval($Message),
50 "numWarnings" => count($this->Warnings),
51 "warnings" => $this->Warnings));
54 private function PrintArrayToJson(array $Array)
56 # variables needed for printing commas if necessary
58 $Count = count($Array);
60 # determine whether or not we have a true array or a hash map
62 for ($i = 0, reset($Array); $i < count($Array); $i++, next($Array))
64 if (key($Array) !== $i)
72 print ($TrueArray) ?
"[" :
"{";
75 foreach ($Array as $key => $value)
77 # replacements so we can escape strings and replace smart quotes
78 static $Replace = array(
79 array(
"\\",
"/",
"\n",
"\t",
"\r",
"\b",
"\f",
'"',
"",
"",
"",
"",
""),
80 array(
'\\\\',
'\\/',
'\\n',
'\\t',
'\\r',
'\\b',
'\\f',
'\"',
"'",
"'",
'\"',
'\"',
'-'));
82 # print key if a hash map
85 # escape, remove smart quotes, and print the key
86 print
'"'.str_replace($Replace[0], $Replace[1], $key).
'":';
89 # scalar values (int, float, string, or boolean)
90 if (is_scalar($value))
92 # numeric (i.e., float, int, or float/int string)
93 if (is_numeric($value))
99 else if (is_string($value))
101 # escape, remove smart quotes, and print the value
102 print
'"'.str_replace($Replace[0], $Replace[1], $value).
'"';
106 else if ($value === TRUE)
112 else if ($value === FALSE)
118 # recur if the value is an array
119 else if (is_array($value))
121 $this->PrintArrayToJson($value);
125 else if (is_null($value))
130 # object, just print the name and don't possibly expose secret details
131 else if (is_object($value))
133 print
'"object('.get_class($value).
')"';
136 # resource, just print the name and don't possibly expose secret details
139 print
'"resource('.get_resource_type($value).
')"';
142 # print comma if necessary
143 if (++$Offset < $Count) { print
","; }
147 print ($TrueArray) ?
"]" :
"}";