- Added JSON type from variables
This commit is contained in:
parent
a768d45a45
commit
9526cb8e2e
49
src/Dump.php
49
src/Dump.php
|
@ -25,7 +25,7 @@ class Dump {
|
|||
|
||||
public function renderArray() {
|
||||
return [
|
||||
'content' => $this->content,
|
||||
'content' => $this->arrayKeysToTypes($this->content),
|
||||
'file' => $this->trace['file'] ?? '?',
|
||||
'line' => $this->trace['line'] ?? '?',
|
||||
'time' => $this->trace['time'],
|
||||
|
@ -62,4 +62,51 @@ HTML;
|
|||
var_dump(...($this->content !== [] ? $this->content : [null]));
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
protected function arrayKeysToTypes(array $content) : array
|
||||
{
|
||||
$newKeys = [];
|
||||
|
||||
foreach($content as $key => $obj) {
|
||||
$newKeys[] = sprintf("%s-%s", $key, $this->typeAsKey($obj));
|
||||
}
|
||||
|
||||
return array_combine($newKeys, $content);
|
||||
}
|
||||
|
||||
protected function typeAsKey(mixed $obj) : string
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
return $obj::class;
|
||||
}
|
||||
elseif (is_array($obj)) {
|
||||
return "array";
|
||||
}
|
||||
elseif (is_string($obj)) {
|
||||
return "string";
|
||||
}
|
||||
elseif (is_int($obj)) {
|
||||
return "integer";
|
||||
}
|
||||
elseif (is_float($obj)) {
|
||||
return "float";
|
||||
}
|
||||
elseif(is_callable($obj)) {
|
||||
return "callable";
|
||||
}
|
||||
elseif(is_bool($obj)) {
|
||||
return "boolean";
|
||||
}
|
||||
elseif(is_double($obj)){
|
||||
return "double";
|
||||
}
|
||||
elseif(is_long($obj)){
|
||||
return "long";
|
||||
}
|
||||
elseif(is_iterable($obj)) {
|
||||
return "iterable";
|
||||
}
|
||||
|
||||
return gettype($obj);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace Dump {
|
|||
break;
|
||||
|
||||
case $response instanceof JsonResponse:
|
||||
foreach(static::$dump_stack as $item) {
|
||||
foreach(static::$dump_stack as $key => $item) {
|
||||
$dump[] = $item->renderArray();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue