diff --git a/src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php b/src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php
index fae3177dfe..4dcb3908e9 100644
--- a/src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php
+++ b/src/Symfony/Bundle/DebugBundle/DependencyInjection/Compiler/DumpDataCollectorPass.php
@@ -11,6 +11,7 @@
namespace Symfony\Bundle\DebugBundle\DependencyInjection\Compiler;
+use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -35,5 +36,9 @@ class DumpDataCollectorPass implements CompilerPassInterface
if ($container->hasParameter('templating.helper.code.file_link_format')) {
$definition->replaceArgument(1, $container->getParameter('templating.helper.code.file_link_format'));
}
+
+ if (!$container->hasParameter('web_profiler.debug_toolbar.mode') || WebDebugToolbarListener::DISABLED === $container->getParameter('web_profiler.debug_toolbar.mode')) {
+ $definition->replaceArgument(3, null);
+ }
}
}
diff --git a/src/Symfony/Bundle/DebugBundle/Resources/config/services.xml b/src/Symfony/Bundle/DebugBundle/Resources/config/services.xml
index 915d510fdc..7de182861b 100644
--- a/src/Symfony/Bundle/DebugBundle/Resources/config/services.xml
+++ b/src/Symfony/Bundle/DebugBundle/Resources/config/services.xml
@@ -15,6 +15,7 @@
null
%kernel.charset%
+
diff --git a/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/Compiler/DumpDataCollectorPassTest.php b/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/Compiler/DumpDataCollectorPassTest.php
index ed3c4c6108..6500a85a84 100644
--- a/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/Compiler/DumpDataCollectorPassTest.php
+++ b/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/Compiler/DumpDataCollectorPassTest.php
@@ -12,8 +12,10 @@
namespace Symfony\Bundle\DebugBundle\Tests\DependencyInjection\Compiler;
use Symfony\Bundle\DebugBundle\DependencyInjection\Compiler\DumpDataCollectorPass;
+use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
+use Symfony\Component\HttpFoundation\RequestStack;
class DumpDataCollectorPassTest extends \PHPUnit_Framework_TestCase
{
@@ -23,7 +25,7 @@ class DumpDataCollectorPassTest extends \PHPUnit_Framework_TestCase
$container->addCompilerPass(new DumpDataCollectorPass());
$container->setParameter('templating.helper.code.file_link_format', 'file-link-format');
- $definition = new Definition('Symfony\Component\HttpKernel\DataCollector\DumpDataCollector', array(null, null));
+ $definition = new Definition('Symfony\Component\HttpKernel\DataCollector\DumpDataCollector', array(null, null, null, null));
$container->setDefinition('data_collector.dump', $definition);
$container->compile();
@@ -36,11 +38,53 @@ class DumpDataCollectorPassTest extends \PHPUnit_Framework_TestCase
$container = new ContainerBuilder();
$container->addCompilerPass(new DumpDataCollectorPass());
- $definition = new Definition('Symfony\Component\HttpKernel\DataCollector\DumpDataCollector', array(null, null));
+ $definition = new Definition('Symfony\Component\HttpKernel\DataCollector\DumpDataCollector', array(null, null, null, null));
$container->setDefinition('data_collector.dump', $definition);
$container->compile();
$this->assertNull($definition->getArgument(1));
}
+
+ public function testProcessWithToolbarEnabled()
+ {
+ $container = new ContainerBuilder();
+ $container->addCompilerPass(new DumpDataCollectorPass());
+ $requestStack = new RequestStack();
+
+ $definition = new Definition('Symfony\Component\HttpKernel\DataCollector\DumpDataCollector', array(null, null, null, $requestStack));
+ $container->setDefinition('data_collector.dump', $definition);
+ $container->setParameter('web_profiler.debug_toolbar.mode', WebDebugToolbarListener::ENABLED);
+
+ $container->compile();
+
+ $this->assertSame($requestStack, $definition->getArgument(3));
+ }
+
+ public function testProcessWithToolbarDisabled()
+ {
+ $container = new ContainerBuilder();
+ $container->addCompilerPass(new DumpDataCollectorPass());
+
+ $definition = new Definition('Symfony\Component\HttpKernel\DataCollector\DumpDataCollector', array(null, null, null, new RequestStack()));
+ $container->setDefinition('data_collector.dump', $definition);
+ $container->setParameter('web_profiler.debug_toolbar.mode', WebDebugToolbarListener::DISABLED);
+
+ $container->compile();
+
+ $this->assertNull($definition->getArgument(3));
+ }
+
+ public function testProcessWithoutToolbar()
+ {
+ $container = new ContainerBuilder();
+ $container->addCompilerPass(new DumpDataCollectorPass());
+
+ $definition = new Definition('Symfony\Component\HttpKernel\DataCollector\DumpDataCollector', array(null, null, null, new RequestStack()));
+ $container->setDefinition('data_collector.dump', $definition);
+
+ $container->compile();
+
+ $this->assertNull($definition->getArgument(3));
+ }
}
diff --git a/src/Symfony/Bundle/DebugBundle/composer.json b/src/Symfony/Bundle/DebugBundle/composer.json
index 66e2fc3233..f9cbcd6266 100644
--- a/src/Symfony/Bundle/DebugBundle/composer.json
+++ b/src/Symfony/Bundle/DebugBundle/composer.json
@@ -24,7 +24,8 @@
"require-dev": {
"symfony/phpunit-bridge": "~2.7",
"symfony/config": "~2.3",
- "symfony/dependency-injection": "~2.3"
+ "symfony/dependency-injection": "~2.3",
+ "symfony/web-profiler-bundle": "~2.3"
},
"suggest": {
"symfony/config": "For service container configuration",
diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php
index 8086226a8b..8352481dbb 100644
--- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php
+++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php
@@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\VarDumper\Cloner\Data;
@@ -33,12 +34,14 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
private $clonesIndex = 0;
private $rootRefs;
private $charset;
+ private $dumper;
- public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, $charset = null)
+ public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, $charset = null, RequestStack $requestStack = null)
{
$this->stopwatch = $stopwatch;
$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->requestStack = $requestStack;
// All clones share these properties by reference:
$this->rootRefs = array(
@@ -118,8 +121,12 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
$name = substr($name, strrpos($name, '/') + 1);
}
- $this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt');
- ++$this->dataCount;
+ if ($this->dumper) {
+ $this->doDump($data, $name, $file, $line);
+ } else {
+ $this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt');
+ ++$this->dataCount;
+ }
if ($this->stopwatch) {
$this->stopwatch->stop('dump');
@@ -128,6 +135,33 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
public function collect(Request $request, Response $response, \Exception $exception = null)
{
+ if ($this->requestStack && $this->requestStack->getMasterRequest() !== $request) {
+ return;
+ }
+
+ // In all conditions that remove the web debug toolbar, dumps are written on the output.
+ if (!$this->requestStack
+ || $request->isXmlHttpRequest()
+ || !$response->headers->has('X-Debug-Token')
+ || $response->isRedirection()
+ || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
+ || 'html' !== $request->getRequestFormat()
+ || false === strripos($response->getContent(), '