Exemple #1
0
 static function dump($data, $indent = null)
 {
     $em = false;
     $type = 'unknown';
     $numeric = true;
     $prefix = $indent > 0 ? str_repeat("\t", $indent) : '';
     if (is_object($data)) {
         $type = 'object';
         if ($data instanceof \Closure) {
             $data = 'Closure';
             $em = true;
         } elseif (in_array($data, self::$_objects)) {
             $data = 'Object recursion';
             $em = true;
         } elseif (!method_exists($data, '__toString')) {
             self::$_objects[] = $data;
             $data = get_object_vars($data);
             $numeric = false;
             if (!$data) {
                 $data = 'Object';
                 $em = true;
             }
         }
     }
     if (is_array($data)) {
         if ($type == 'unknown') {
             $type = 'array';
         }
         $lines = array();
         if ($numeric) {
             $numeric = Utils::arrayIsNumeric($data);
         }
         foreach ($data as $key => $value) {
             $lines[] = ($numeric ? '' : "<strong>{$key}</strong>: ") . self::dump($value, $indent + 1);
         }
         $data = implode("</li>\n{$prefix}<li>", $lines);
         if ($data) {
             $data = "<li>{$data}</li>";
         }
         if (!$data) {
             $data = "Empty array";
             $em = true;
         } else {
             $data = $numeric ? "\n{$prefix}<ol>{$data}</ol>\n" : "\n{$prefix}<ul>{$data}</ul>\n";
         }
     } else {
         if (is_bool($data)) {
             $type = 'bool';
             $data = $data ? 'TRUE' : 'FALSE';
             $em = true;
         } elseif ($data === null) {
             $type = 'null';
             $data = 'NULL';
             $em = true;
         } elseif (is_int($data)) {
             $type = 'int';
             $em = true;
         } elseif (is_float($data)) {
             $type = 'float';
             $em = true;
         } elseif (is_resource($data)) {
             $type = 'resource';
             $data = 'RESOURCE';
             $em = true;
         } elseif (is_string($data)) {
             if ($type == 'unknown') {
                 $type = 'string';
             }
             if (preg_match('`^https?://[^\\s]+$`', $data)) {
                 $data = Utils::htmlentities($data);
                 $data = "<a href='{$data}'>{$data}</a>";
             } else {
                 $data = Utils::htmlentities($data);
             }
         }
     }
     if ($em) {
         $data = "<em class='dump-{$type}'>{$data}</em>";
     } else {
         $data = "<span class='dump-{$type}'>{$data}</span>";
     }
     if ($indent === null) {
         self::$_objects = array();
         $data = "<div class='dump'>{$data}</div>";
     }
     return (string) $data;
 }