mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-01-29 11:17:52 +01:00
commit
b51fc22937
@ -12,8 +12,7 @@
|
||||
}],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"psr/log": "~1.0",
|
||||
"raveren/kint": "0.9"
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"php": ">=5.3.0"
|
||||
|
@ -14,7 +14,7 @@ class DataFormatter implements DataFormatterInterface
|
||||
{
|
||||
public function formatVar($data)
|
||||
{
|
||||
return \kintLite($data);
|
||||
return $this->kintLite($data);
|
||||
}
|
||||
|
||||
public function formatDuration($seconds)
|
||||
@ -36,4 +36,138 @@ class DataFormatter implements DataFormatterInterface
|
||||
$suffixes = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
||||
}
|
||||
|
||||
/**
|
||||
* lightweight version of Kint::dump(). Uses whitespace for formatting instead of html
|
||||
* sadly not DRY yet
|
||||
*
|
||||
* Extracted from Kint.class.php in raveren/kint, https://github.com/raveren/kint
|
||||
* Copyright (c) 2013 Rokas Šleinius (raveren@gmail.com)
|
||||
*
|
||||
* @param mixed $var
|
||||
* @param int $level
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function kintLite(&$var, $level = 0)
|
||||
{
|
||||
// initialize function names into variables for prettier string output (html and implode are also DRY)
|
||||
$html = "htmlspecialchars";
|
||||
$implode = "implode";
|
||||
$strlen = "strlen";
|
||||
$count = "count";
|
||||
$getClass = "get_class";
|
||||
|
||||
|
||||
if ( $var === null ) {
|
||||
return 'NULL';
|
||||
} elseif ( is_bool( $var ) ) {
|
||||
return 'bool ' . ( $var ? 'TRUE' : 'FALSE' );
|
||||
} elseif ( is_float( $var ) ) {
|
||||
return 'float ' . $var;
|
||||
} elseif ( is_int( $var ) ) {
|
||||
return 'integer ' . $var;
|
||||
} elseif ( is_resource( $var ) ) {
|
||||
if ( ( $type = get_resource_type( $var ) ) === 'stream' AND $meta = stream_get_meta_data( $var ) ) {
|
||||
|
||||
if ( isset( $meta['uri'] ) ) {
|
||||
$file = $meta['uri'];
|
||||
|
||||
return "resource ({$type}) {$html( $file, 0 )}";
|
||||
} else {
|
||||
return "resource ({$type})";
|
||||
}
|
||||
} else {
|
||||
return "resource ({$type})";
|
||||
}
|
||||
} elseif ( is_string( $var ) ) {
|
||||
return "string ({$strlen( $var )}) \"{$html( $var )}\"";
|
||||
} elseif ( is_array( $var ) ) {
|
||||
$output = array();
|
||||
$space = str_repeat( $s = ' ', $level );
|
||||
|
||||
static $marker;
|
||||
|
||||
if ( $marker === null ) {
|
||||
// Make a unique marker
|
||||
$marker = uniqid( "\x00" );
|
||||
}
|
||||
|
||||
if ( empty( $var ) ) {
|
||||
return "array()";
|
||||
} elseif ( isset( $var[$marker] ) ) {
|
||||
$output[] = "[\n$space$s*RECURSION*\n$space]";
|
||||
} elseif ( $level < 7 ) {
|
||||
$isSeq = array_keys( $var ) === range( 0, count( $var ) - 1 );
|
||||
|
||||
$output[] = "[";
|
||||
|
||||
$var[$marker] = true;
|
||||
|
||||
|
||||
foreach ( $var as $key => &$val ) {
|
||||
if ( $key === $marker ) continue;
|
||||
|
||||
$key = $space . $s . ( $isSeq ? "" : "'{$html( $key, 0 )}' => " );
|
||||
|
||||
$dump = $this->kintLite( $val, $level + 1 );
|
||||
$output[] = "{$key}{$dump}";
|
||||
}
|
||||
|
||||
unset( $var[$marker] );
|
||||
$output[] = "$space]";
|
||||
|
||||
} else {
|
||||
$output[] = "[\n$space$s*depth too great*\n$space]";
|
||||
}
|
||||
return "array({$count( $var )}) {$implode( "\n", $output )}";
|
||||
} elseif ( is_object( $var ) ) {
|
||||
if ( $var instanceof SplFileInfo ) {
|
||||
return "object SplFileInfo " . $var->getRealPath();
|
||||
}
|
||||
|
||||
// Copy the object as an array
|
||||
$array = (array)$var;
|
||||
|
||||
$output = array();
|
||||
$space = str_repeat( $s = ' ', $level );
|
||||
|
||||
$hash = spl_object_hash( $var );
|
||||
|
||||
// Objects that are being dumped
|
||||
static $objects = array();
|
||||
|
||||
if ( empty( $array ) ) {
|
||||
return "object {$getClass( $var )} {}";
|
||||
} elseif ( isset( $objects[$hash] ) ) {
|
||||
$output[] = "{\n$space$s*RECURSION*\n$space}";
|
||||
} elseif ( $level < 7 ) {
|
||||
$output[] = "{";
|
||||
$objects[$hash] = true;
|
||||
|
||||
foreach ( $array as $key => & $val ) {
|
||||
if ( $key[0] === "\x00" ) {
|
||||
|
||||
$access = $key[1] === "*" ? "protected" : "private";
|
||||
|
||||
// Remove the access level from the variable name
|
||||
$key = substr( $key, strrpos( $key, "\x00" ) + 1 );
|
||||
} else {
|
||||
$access = "public";
|
||||
}
|
||||
|
||||
$output[] = "$space$s$access $key -> " . $this->kintLite( $val, $level + 1 );
|
||||
}
|
||||
unset( $objects[$hash] );
|
||||
$output[] = "$space}";
|
||||
|
||||
} else {
|
||||
$output[] = "{\n$space$s*depth too great*\n$space}";
|
||||
}
|
||||
|
||||
return "object {$getClass( $var )} ({$count( $array )}) {$implode( "\n", $output )}";
|
||||
} else {
|
||||
return gettype( $var ) . htmlspecialchars( var_export( $var, true ), ENT_NOQUOTES );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user