printable() public static method

Returns a string that can be printed, replaces non-printable characters
public static printable ( $str ) : string
$str
return string
Example #1
0
 public function __debugInfo()
 {
     $data = [];
     foreach ($this as $k => $v) {
         if ($k === "buffer") {
             $data[$k] = bin2hex($v);
         } elseif (is_string($v) or is_object($v) and method_exists($v, "__toString")) {
             $data[$k] = Utils::printable((string) $v);
         } else {
             $data[$k] = $v;
         }
     }
     return $data;
 }
 function getTrace($start = 1, $trace = \null)
 {
     if ($trace === \null) {
         if (\function_exists("xdebug_get_function_stack")) {
             $trace = \array_reverse(xdebug_get_function_stack());
         } else {
             $e = new \Exception();
             $trace = $e->getTrace();
         }
     }
     $messages = [];
     $j = 0;
     for ($i = (int) $start; isset($trace[$i]); ++$i, ++$j) {
         $params = "";
         if (isset($trace[$i]["args"]) or isset($trace[$i]["params"])) {
             if (isset($trace[$i]["args"])) {
                 $args = $trace[$i]["args"];
             } else {
                 $args = $trace[$i]["params"];
             }
             foreach ($args as $name => $value) {
                 $params .= (\is_object($value) ? \get_class($value) . " " . (\method_exists($value, "__toString") ? $value->__toString() : "object") : \gettype($value) . " " . (\is_array($value) ? "Array()" : Utils::printable(@\strval($value)))) . ", ";
             }
         }
         $messages[] = "#{$j} " . (isset($trace[$i]["file"]) ? cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable(\substr($params, 0, -2)) . ")";
     }
     return $messages;
 }
Example #3
0
 private function continueDump($from, &$data, &$objects, &$refCounts, $recursion, $maxNesting, $maxStringSize)
 {
     if ($maxNesting <= 0) {
         $data = "(error) NESTING LIMIT REACHED";
         return;
     }
     --$maxNesting;
     if (is_object($from)) {
         if (!isset($objects[$hash = spl_object_hash($from)])) {
             $objects[$hash] = $from;
             $refCounts[$hash] = 0;
         }
         ++$refCounts[$hash];
         $data = "(object) {$hash}@" . get_class($from);
     } elseif (is_array($from)) {
         if ($recursion >= 5) {
             $data = "(error) ARRAY RECURSION LIMIT REACHED";
             return;
         }
         $data = [];
         foreach ($from as $key => $value) {
             $this->continueDump($value, $data[$key], $objects, $refCounts, $recursion + 1, $maxNesting, $maxStringSize);
         }
     } elseif (is_string($from)) {
         $data = "(string) len(" . strlen($from) . ") " . substr(Utils::printable($from), 0, $maxStringSize);
     } elseif (is_resource($from)) {
         $data = "(resource) " . print_r($from, true);
     } else {
         $data = $from;
     }
 }
Example #4
0
 private function fromArray(Tag $tag, array $data)
 {
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             $isNumeric = true;
             $isIntArray = true;
             foreach ($value as $k => $v) {
                 if (!is_numeric($k)) {
                     $isNumeric = false;
                     break;
                 } elseif (!is_int($v)) {
                     $isIntArray = false;
                 }
             }
             $tag[$key] = $isNumeric ? $isIntArray ? new IntArray($key, []) : new Enum($key, []) : new Compound($key, []);
             $this->fromArray($tag->{$key}, $value);
         } elseif (is_int($value)) {
             $tag[$key] = new Int($key, $value);
         } elseif (is_float($value)) {
             $tag[$key] = new Float($key, $value);
         } elseif (is_string($value)) {
             if (Utils::printable($value) !== $value) {
                 $tag[$key] = new ByteArray($key, $value);
             } else {
                 $tag[$key] = new String($key, $value);
             }
         } elseif (is_bool($value)) {
             $tag[$key] = new Byte($key, $value ? 1 : 0);
         }
     }
 }