- Added JSON type from variables

This commit is contained in:
Dave Mc Nicoll committed 2024-12-02 15:25:29 -05:00
1 parent a768d45a45
commit 947110c7c9
2 files changed
+49 -2

No files matched your search

+48 -1
View File
@@ -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);
}
}
+1 -1
View File
@@ -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();
}