Changeset View
Changeset View
Standalone View
Standalone View
src/applications/console/core/DarkConsoleCore.php
| Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | final class DarkConsoleCore extends Phobject { | ||||
| private function sanitizeForJSON($data) { | private function sanitizeForJSON($data) { | ||||
| if (is_object($data)) { | if (is_object($data)) { | ||||
| return '<object:'.get_class($data).'>'; | return '<object:'.get_class($data).'>'; | ||||
| } else if (is_array($data)) { | } else if (is_array($data)) { | ||||
| foreach ($data as $key => $value) { | foreach ($data as $key => $value) { | ||||
| $data[$key] = $this->sanitizeForJSON($value); | $data[$key] = $this->sanitizeForJSON($value); | ||||
| } | } | ||||
| return $data; | return $data; | ||||
| } else if (is_resource($data)) { | |||||
| return '<resource>'; | |||||
| } else { | } else { | ||||
| // Truncate huge strings. Since the data doesn't really matter much, | // Truncate huge strings. Since the data doesn't really matter much, | ||||
| // just truncate bytes to avoid PhutilUTF8StringTruncator overhead. | // just truncate bytes to avoid PhutilUTF8StringTruncator overhead. | ||||
| $length = strlen($data); | $length = strlen($data); | ||||
| $max = 4096; | $max = 4096; | ||||
| if ($length > $max) { | if ($length > $max) { | ||||
| $data = substr($data, 0, $max).'...<'.$length.' bytes>...'; | $data = substr($data, 0, $max).'...<'.$length.' bytes>...'; | ||||
| } | } | ||||
| return phutil_utf8ize($data); | return phutil_utf8ize($data); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||