php-debugbar icon indicating copy to clipboard operation
php-debugbar copied to clipboard

Solution for timed PDO calls with StandardDebugBar?

Open igorsantos07 opened this issue 7 years ago • 0 comments

According to docs, it's possible to time all PDO calls if this collector is created before TimeData.

However, the PDO collector is optional on the "Standard package", while TimeData comes on it. This complicates the use of StandardDebugBar, as there's no way to re-register a collector, nor unregister. Simply to get PDO timing, one needs to drop StandardDebugBar (which is the easiest and cleanest way to setup DebugBar) and bring a lenghty list of imports / addCollector calls into the current code.

I can't get a single solution for this, so I'm opening an issue instead, with some suggestions:

  • receive an argument on StandardDebugBar with a list of extra collectors to register, which come before the default ones
  • allow unregistering a collector
  • allow overwriting of a collector
  • perhaps allow PDOCollector to tap into TimeDataCollector and say "hey, I'm around now"?

use \DebugBar\DataCollector\PDO as PDODebug;
//"default" setup
$debugbar = new \DebugBar\StandardDebugBar;
$debugbar
	->addCollector(new PDODebug\PDOCollector(new PDODebug\TraceablePDO($pdo)))
	->getJavascriptRenderer('/web/debugbar', CORE_PATH.'/web/debugbar')
	->renderOnShutdownWithHead();

//timed PDO setup
$timeCollector = new \DebugBar\DataCollector\TimeDataCollector;
$debugbar = new \DebugBar\DebugBar;
$debugbar
	->addCollector(new \DebugBar\DataCollector\PhpInfoCollector)
	->addCollector(new \DebugBar\DataCollector\MessagesCollector)
	->addCollector(new \DebugBar\DataCollector\RequestDataCollector)
	->addCollector(new \DebugBar\DataCollector\MemoryCollector)
	->addCollector(new \DebugBar\DataCollector\ExceptionsCollector)
	->addCollector(new \DebugBar\DataCollector\PDO\PDOCollector($pdo, $timeCollector))
	->addCollector($timeCollector) //this comes last so it also times PDO
	->getJavascriptRenderer('/web/debugbar', CORE_PATH.'/web/debugbar')
	->renderOnShutdownWithHead();

igorsantos07 avatar Jan 20 '19 23:01 igorsantos07