[Debug] Swap dumper services at bootstrap

This commit fix a bug when using debug function too soon.
For example, if you call dump function during kernel::boot() the
dump output will be sent to stderr, even in a web context.

With this patch, the data collector is used by default, so the
dump output is send to the WDT. In a CLI context, if dump is used
too soon, the datacollector will buffer it, and release it at the
end of the script. So in this case everything will be visible by the
end used.
This commit is contained in:
Grégoire Pineau 2016-08-17 12:11:24 +02:00
parent adb7033fc2
commit d80589c2d4
4 changed files with 6 additions and 6 deletions

View File

@ -30,7 +30,7 @@ class DebugBundle extends Bundle
// configuration for CLI mode is overridden in HTTP mode on
// 'kernel.request' event
VarDumper::setHandler(function ($var) use ($container) {
$dumper = $container->get('var_dumper.cli_dumper');
$dumper = $container->get('data_collector.dump');
$cloner = $container->get('var_dumper.cloner');
$handler = function ($var) use ($dumper, $cloner) {
$dumper->dump($cloner->cloneVar($var));

View File

@ -22,7 +22,7 @@
<service id="debug.dump_listener" class="Symfony\Component\HttpKernel\EventListener\DumpListener">
<tag name="kernel.event_subscriber" />
<argument type="service" id="var_dumper.cloner" />
<argument type="service" id="data_collector.dump" />
<argument type="service" id="var_dumper.cli_dumper" />
</service>
<service id="var_dumper.cloner" class="Symfony\Component\VarDumper\Cloner\VarCloner" />

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
use Symfony\Component\VarDumper\VarDumper;
@ -50,6 +50,6 @@ class DumpListener implements EventSubscriberInterface
public static function getSubscribedEvents()
{
// Register early to have a working dump() as early as possible
return array(KernelEvents::REQUEST => array('configure', 1024));
return array(ConsoleEvents::COMMAND => array('configure', 1024));
}
}

View File

@ -11,8 +11,8 @@
namespace Symfony\Component\HttpKernel\Tests\EventListener;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\HttpKernel\EventListener\DumpListener;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
@ -28,7 +28,7 @@ class DumpListenerTest extends \PHPUnit_Framework_TestCase
public function testSubscribedEvents()
{
$this->assertSame(
array(KernelEvents::REQUEST => array('configure', 1024)),
array(ConsoleEvents::COMMAND => array('configure', 1024)),
DumpListener::getSubscribedEvents()
);
}