-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Yiisoft\VarDumper\VarDumper; | ||
use Yiisoft\Yii\Debug\Collector\VarDumperCollector; | ||
use Yiisoft\Yii\Debug\Collector\VarDumperHandlerInterfaceProxy; | ||
|
||
/** | ||
* @var $params array | ||
*/ | ||
|
||
return [ | ||
static function ($container) use ($params) { | ||
if (!($params['yiisoft/yii-debug']['enabled'] ?? false)) { | ||
return; | ||
} | ||
if (!$container->has(VarDumperCollector::class)) { | ||
return; | ||
} | ||
|
||
VarDumper::setDefaultHandler( | ||
new VarDumperHandlerInterfaceProxy( | ||
VarDumper::getDefaultHandler(), | ||
$container->get(VarDumperCollector::class), | ||
), | ||
); | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Debug\Collector; | ||
|
||
final class VarDumperCollector implements SummaryCollectorInterface | ||
{ | ||
use CollectorTrait; | ||
|
||
private array $vars = []; | ||
|
||
public function collectVar(mixed $variable, string $line): void | ||
{ | ||
$this->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), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Debug\Collector; | ||
|
||
use Yiisoft\VarDumper\HandlerInterface; | ||
|
||
final class VarDumperHandlerInterfaceProxy implements HandlerInterface | ||
Check failure on line 9 in src/Collector/VarDumperHandlerInterfaceProxy.php GitHub Actions / psalm / PHP 8.0-ubuntu-latestUndefinedClass
Check failure on line 9 in src/Collector/VarDumperHandlerInterfaceProxy.php GitHub Actions / psalm / PHP 8.1-ubuntu-latestUndefinedClass
Check failure on line 9 in src/Collector/VarDumperHandlerInterfaceProxy.php GitHub Actions / psalm / PHP 8.0-ubuntu-latestUndefinedClass
Check failure on line 9 in src/Collector/VarDumperHandlerInterfaceProxy.php GitHub Actions / psalm / PHP 8.1-ubuntu-latestUndefinedClass
|
||
{ | ||
public function __construct( | ||
private HandlerInterface $decorated, | ||
private VarDumperCollector $collector, | ||
) { | ||
} | ||
|
||
public function handle(mixed $variable, int $depth, bool $highlight = false): void | ||
{ | ||
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); | ||
|
||
$callStack = null; | ||
foreach ($stack as $value) { | ||
if (!isset($value['file'])) { | ||
continue; | ||
} | ||
if (str_ends_with($value['file'], '/var-dumper/src/functions.php')) { | ||
continue; | ||
} | ||
if (str_ends_with($value['file'], '/var-dumper/src/VarDumper.php')) { | ||
continue; | ||
} | ||
$callStack = $value; | ||
break; | ||
} | ||
|
||
$this->collector->collectVar( | ||
$variable, | ||
$callStack === null ? '' : $callStack['file'] . ':' . $callStack['line'] | ||
); | ||
$this->decorated->handle($variable, $depth, $highlight); | ||
} | ||
} |