Compare commits
5
Commits
6c074a249e
..
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9526cb8e2e | ||
|
|
a768d45a45 | ||
|
|
401fe15c18 | ||
|
|
eb378eb21e | ||
|
|
b99ff24d26 |
No files matched your search
@@ -13,5 +13,14 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Dump\\": "src/"
|
"Dump\\": "src/"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"lean": {
|
||||||
|
"autoload": {
|
||||||
|
"definitions" : [
|
||||||
|
"meta/definitions.php"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use function DI\autowire, DI\create, DI\get;
|
||||||
|
|
||||||
|
use Dump\Picea\DumpExtension;
|
||||||
|
|
||||||
|
return [
|
||||||
|
DumpExtension::class => autowire(DumpExtension::class),
|
||||||
|
];
|
||||||
+53
-5
@@ -15,19 +15,20 @@ class Dump {
|
|||||||
protected $content = null;
|
protected $content = null;
|
||||||
|
|
||||||
public function __construct(...$content) {
|
public function __construct(...$content) {
|
||||||
$this->trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2] ?? [
|
$this->trace = (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2] ?? [
|
||||||
"line" => -1,
|
"line" => -1,
|
||||||
"file" => "unknown",
|
"file" => "unknown",
|
||||||
];
|
]) + [ 'time' => round(1000 * (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 4) ];
|
||||||
|
|
||||||
$this->content = $content;
|
$this->content = $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderArray() {
|
public function renderArray() {
|
||||||
return [
|
return [
|
||||||
'content' => $this->content,
|
'content' => $this->arrayKeysToTypes($this->content),
|
||||||
'file' => $this->trace['file'] ?? '?',
|
'file' => $this->trace['file'] ?? '?',
|
||||||
'line' => $this->trace['line'] ?? '?',
|
'line' => $this->trace['line'] ?? '?',
|
||||||
|
'time' => $this->trace['time'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ class Dump {
|
|||||||
|
|
||||||
return <<<HTML
|
return <<<HTML
|
||||||
<pre style='-webkit-overflow-scrolling: touch;background-color: #f5f5f5;color: #4a4a4a;font-size: 12px;line-height:18px;overflow-x: auto;padding: 0.5rem 1.5rem;word-wrap: normal;white-space: pre;margin:0.33rem 0;position: relative;z-index:9999999999;'>
|
<pre style='-webkit-overflow-scrolling: touch;background-color: #f5f5f5;color: #4a4a4a;font-size: 12px;line-height:18px;overflow-x: auto;padding: 0.5rem 1.5rem;word-wrap: normal;white-space: pre;margin:0.33rem 0;position: relative;z-index:9999999999;'>
|
||||||
<div style='color:#9f9f9f;font-size:10px;' title='{$this->trace['file']}'>[ file: {$this->trace['file']}:{$this->trace['line']} ]</div>
|
<div style='color:#9f9f9f;font-size:10px;' title='{$this->trace['file']}'>[ file: {$this->trace['file']}:{$this->trace['line']} ] <small>timestamp: {$this->trace['time']}</small></div>
|
||||||
$data
|
$data
|
||||||
</pre>
|
</pre>
|
||||||
HTML;
|
HTML;
|
||||||
@@ -51,7 +52,7 @@ HTML;
|
|||||||
$this->trace['file'] ??= "?";
|
$this->trace['file'] ??= "?";
|
||||||
$this->trace['line'] ??= "?";
|
$this->trace['line'] ??= "?";
|
||||||
|
|
||||||
$header = "File: {$this->trace['file']} | line : {$this->trace['line']}";
|
$header = "File: {$this->trace['file']} | line : {$this->trace['line']} | time : {$this->trace['time']}";
|
||||||
|
|
||||||
return str_repeat('-', strlen($header)) . PHP_EOL . $header . PHP_EOL . str_repeat('-', strlen($header)) . PHP_EOL . $data . PHP_EOL;
|
return str_repeat('-', strlen($header)) . PHP_EOL . $header . PHP_EOL . str_repeat('-', strlen($header)) . PHP_EOL . $data . PHP_EOL;
|
||||||
}
|
}
|
||||||
@@ -61,4 +62,51 @@ HTML;
|
|||||||
var_dump(...($this->content !== [] ? $this->content : [null]));
|
var_dump(...($this->content !== [] ? $this->content : [null]));
|
||||||
return ob_get_clean();
|
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,12 +47,14 @@ namespace Dump {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case $response instanceof JsonResponse:
|
case $response instanceof JsonResponse:
|
||||||
foreach(static::$dump_stack as $item) {
|
foreach(static::$dump_stack as $key => $item) {
|
||||||
$dump[] = $item->renderArray();
|
$dump[] = $item->renderArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($dump)) {
|
if (isset($dump)) {
|
||||||
$stream->write(json_encode(array_merge(["_dump" => $dump ?? []], json_decode($body->getContents() ?? "{}", true)), JsonResponse::DEFAULT_JSON_FLAGS));
|
$json = json_encode(array_merge(["_dump" => $dump ], json_decode($body->getContents() ?? "{}", true)), JsonResponse::DEFAULT_JSON_FLAGS);
|
||||||
|
|
||||||
|
$stream->write(! is_string($json) ? json_encode($json, JsonResponse::DEFAULT_JSON_FLAGS) : $json);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stream->append_resource($body->detach());
|
$stream->append_resource($body->detach());
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Dump\Picea;
|
||||||
|
|
||||||
|
use Picea\{ Extension\Extension, Extension\FunctionExtension };
|
||||||
|
|
||||||
|
class DumpExtension implements Extension {
|
||||||
|
|
||||||
|
public array $token = [ "dump" ];
|
||||||
|
|
||||||
|
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
||||||
|
{
|
||||||
|
return "<?php \dump($arguments) ?>";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user