[DebugBundle] Allow alternative destination for dumps
This commit is contained in:
parent
5368483d9a
commit
5f255e5059
@ -14,7 +14,6 @@ namespace Symfony\Bundle\DebugBundle;
|
|||||||
use Symfony\Bundle\DebugBundle\DependencyInjection\Compiler\DumpDataCollectorPass;
|
use Symfony\Bundle\DebugBundle\DependencyInjection\Compiler\DumpDataCollectorPass;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
|
||||||
use Symfony\Component\VarDumper\VarDumper;
|
use Symfony\Component\VarDumper\VarDumper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +30,7 @@ class DebugBundle extends Bundle
|
|||||||
// configuration for CLI mode is overridden in HTTP mode on
|
// configuration for CLI mode is overridden in HTTP mode on
|
||||||
// 'kernel.request' event
|
// 'kernel.request' event
|
||||||
VarDumper::setHandler(function ($var) use ($container) {
|
VarDumper::setHandler(function ($var) use ($container) {
|
||||||
$dumper = new CliDumper();
|
$dumper = $container->get('var_dumper.cli_dumper');
|
||||||
$cloner = $container->get('var_dumper.cloner');
|
$cloner = $container->get('var_dumper.cloner');
|
||||||
$handler = function ($var) use ($dumper, $cloner) {
|
$handler = function ($var) use ($dumper, $cloner) {
|
||||||
$dumper->dump($cloner->cloneVar($var));
|
$dumper->dump($cloner->cloneVar($var));
|
||||||
|
@ -41,6 +41,11 @@ class Configuration implements ConfigurationInterface
|
|||||||
->min(-1)
|
->min(-1)
|
||||||
->defaultValue(-1)
|
->defaultValue(-1)
|
||||||
->end()
|
->end()
|
||||||
|
->scalarNode('dump_destination')
|
||||||
|
->info('A stream URL where dumps should be written to')
|
||||||
|
->example('php://stderr')
|
||||||
|
->defaultNull()
|
||||||
|
->end()
|
||||||
->end()
|
->end()
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Bundle\DebugBundle\DependencyInjection;
|
|||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,6 +38,15 @@ class DebugExtension extends Extension
|
|||||||
$container->getDefinition('var_dumper.cloner')
|
$container->getDefinition('var_dumper.cloner')
|
||||||
->addMethodCall('setMaxItems', array($config['max_items']))
|
->addMethodCall('setMaxItems', array($config['max_items']))
|
||||||
->addMethodCall('setMaxString', array($config['max_string_length']));
|
->addMethodCall('setMaxString', array($config['max_string_length']));
|
||||||
|
|
||||||
|
if (null !== $config['dump_destination']) {
|
||||||
|
$container->getDefinition('var_dumper.cli_dumper')
|
||||||
|
->replaceArgument(0, $config['dump_destination'])
|
||||||
|
;
|
||||||
|
$container->getDefinition('data_collector.dump')
|
||||||
|
->replaceArgument(4, new Reference('var_dumper.cli_dumper'))
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
<argument>null</argument><!-- %templating.helper.code.file_link_format% -->
|
<argument>null</argument><!-- %templating.helper.code.file_link_format% -->
|
||||||
<argument>%kernel.charset%</argument>
|
<argument>%kernel.charset%</argument>
|
||||||
<argument type="service" id="request_stack" />
|
<argument type="service" id="request_stack" />
|
||||||
|
<argument>null</argument><!-- var_dumper.cli_dumper when debug.dump_destination is set -->
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="debug.dump_listener" class="Symfony\Component\HttpKernel\EventListener\DumpListener">
|
<service id="debug.dump_listener" class="Symfony\Component\HttpKernel\EventListener\DumpListener">
|
||||||
@ -25,6 +26,10 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="var_dumper.cloner" class="Symfony\Component\VarDumper\Cloner\VarCloner" />
|
<service id="var_dumper.cloner" class="Symfony\Component\VarDumper\Cloner\VarCloner" />
|
||||||
|
<service id="var_dumper.cli_dumper" class="Symfony\Component\VarDumper\Dumper\CliDumper">
|
||||||
|
<argument>null</argument><!-- debug.dump_destination -->
|
||||||
|
<argument>%kernel.charset%</argument>
|
||||||
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</container>
|
</container>
|
||||||
|
@ -35,13 +35,16 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
|||||||
private $rootRefs;
|
private $rootRefs;
|
||||||
private $charset;
|
private $charset;
|
||||||
private $dumper;
|
private $dumper;
|
||||||
|
private $dumperIsInjected;
|
||||||
|
|
||||||
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, $charset = null, RequestStack $requestStack = null)
|
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, $charset = null, RequestStack $requestStack = null, DataDumperInterface $dumper = null)
|
||||||
{
|
{
|
||||||
$this->stopwatch = $stopwatch;
|
$this->stopwatch = $stopwatch;
|
||||||
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
||||||
$this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8';
|
$this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8';
|
||||||
$this->requestStack = $requestStack;
|
$this->requestStack = $requestStack;
|
||||||
|
$this->dumper = $dumper;
|
||||||
|
$this->dumperIsInjected = null !== $dumper;
|
||||||
|
|
||||||
// All clones share these properties by reference:
|
// All clones share these properties by reference:
|
||||||
$this->rootRefs = array(
|
$this->rootRefs = array(
|
||||||
@ -170,7 +173,9 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
|||||||
$this->data = array();
|
$this->data = array();
|
||||||
$this->dataCount = 0;
|
$this->dataCount = 0;
|
||||||
$this->isCollected = true;
|
$this->isCollected = true;
|
||||||
$this->dumper = null;
|
if (!$this->dumperIsInjected) {
|
||||||
|
$this->dumper = null;
|
||||||
|
}
|
||||||
|
|
||||||
return $ser;
|
return $ser;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user