mirror of
https://github.com/dg/dibi.git
synced 2025-02-24 02:43:09 +01:00
DibiProfiler: json_encode in native in PHP 5.2
This commit is contained in:
parent
0b9562497f
commit
22d41ca3c1
@ -135,7 +135,7 @@ class DibiProfiler extends DibiObject implements IDibiProfiler
|
||||
),
|
||||
self::$table,
|
||||
);
|
||||
$payload = function_exists('json_encode') ? json_encode($payload) : self::json_encode($payload);
|
||||
$payload = json_encode($payload);
|
||||
foreach (str_split($payload, 4990) as $num => $s) {
|
||||
$num++;
|
||||
header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index
|
||||
@ -198,39 +198,4 @@ class DibiProfiler extends DibiObject implements IDibiProfiler
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function json_encode($val)
|
||||
{
|
||||
// indexed array
|
||||
if (is_array($val) && (!$val
|
||||
|| array_keys($val) === range(0, count($val) - 1))) {
|
||||
return '[' . implode(',', array_map(array(__CLASS__, 'json_encode'), $val)) . ']';
|
||||
}
|
||||
|
||||
// associative array
|
||||
if (is_array($val) || is_object($val)) {
|
||||
$tmp = array();
|
||||
foreach ($val as $k => $v) {
|
||||
$tmp[] = self::json_encode((string) $k) . ':' . self::json_encode($v);
|
||||
}
|
||||
return '{' . implode(',', $tmp) . '}';
|
||||
}
|
||||
|
||||
if (is_string($val)) {
|
||||
$val = str_replace(array("\\", "\x00"), array("\\\\", "\\u0000"), $val); // due to bug #40915
|
||||
return '"' . addcslashes($val, "\x8\x9\xA\xC\xD/\"") . '"';
|
||||
}
|
||||
|
||||
if (is_int($val) || is_float($val)) {
|
||||
return rtrim(rtrim(number_format($val, 5, '.', ''), '0'), '.');
|
||||
}
|
||||
|
||||
if (is_bool($val)) {
|
||||
return $val ? 'true' : 'false';
|
||||
}
|
||||
|
||||
return 'null';
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user