diff --git a/config/bootstrap.php b/config/bootstrap.php new file mode 100644 index 00000000..a78e5b21 --- /dev/null +++ b/config/bootstrap.php @@ -0,0 +1,29 @@ +has(VarDumperCollector::class)) { + return; + } + + VarDumper::setDefaultHandler( + new VarDumperHandlerInterfaceProxy( + VarDumper::getDefaultHandler(), + $container->get(VarDumperCollector::class), + ), + ); + }, +]; diff --git a/config/params.php b/config/params.php index b2f92802..08a65b97 100644 --- a/config/params.php +++ b/config/params.php @@ -21,6 +21,7 @@ use Yiisoft\Yii\Debug\Collector\ServiceCollector; use Yiisoft\Yii\Debug\Collector\Stream\FilesystemStreamCollector; use Yiisoft\Yii\Debug\Collector\Stream\HttpStreamCollector; +use Yiisoft\Yii\Debug\Collector\VarDumperCollector; use Yiisoft\Yii\Debug\Collector\Web\MiddlewareCollector; use Yiisoft\Yii\Debug\Collector\Web\RequestCollector; use Yiisoft\Yii\Debug\Collector\Web\WebAppInfoCollector; @@ -43,6 +44,7 @@ FilesystemStreamCollector::class, HttpStreamCollector::class, ExceptionCollector::class, + VarDumperCollector::class, ], 'collectors.web' => [ WebAppInfoCollector::class, diff --git a/src/Collector/VarDumperCollector.php b/src/Collector/VarDumperCollector.php new file mode 100644 index 00000000..4575cf9e --- /dev/null +++ b/src/Collector/VarDumperCollector.php @@ -0,0 +1,44 @@ +vars[] = [ + 'variable' => $variable, + 'line' => $line, + ]; + } + + public function getCollected(): array + { + if (!$this->isActive()) { + return []; + } + + return [ + 'var-dumper' => $this->vars, + ]; + } + + public function getSummary(): array + { + if (!$this->isActive()) { + return []; + } + + return [ + 'var-dumper' => [ + 'total' => count($this->vars), + ], + ]; + } +} diff --git a/src/Collector/VarDumperHandlerInterfaceProxy.php b/src/Collector/VarDumperHandlerInterfaceProxy.php new file mode 100644 index 00000000..cd284881 --- /dev/null +++ b/src/Collector/VarDumperHandlerInterfaceProxy.php @@ -0,0 +1,42 @@ +collector->collectVar( + $variable, + $callStack === null ? '' : $callStack['file'] . ':' . $callStack['line'] + ); + $this->decorated->handle($variable, $depth, $highlight); + } +}