From 8cb2abbd269574caa1cd76b73c8efdcd6cc470b2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 13 May 2015 12:14:36 +0200 Subject: [PATCH 1/3] [DebugBundle] Always collect dumps --- .../HttpKernel/DataCollector/DumpDataCollector.php | 14 +++++--------- .../Tests/DataCollector/DumpDataCollectorTest.php | 4 ++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index 0327a46f71701..c4101e2d62919 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -123,11 +123,11 @@ public function dump(Data $data) if ($this->dumper) { $this->doDump($data, $name, $file, $line); - } else { - $this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt'); - ++$this->dataCount; } + $this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt'); + ++$this->dataCount; + if ($this->stopwatch) { $this->stopwatch->stop('dump'); } @@ -136,7 +136,7 @@ public function dump(Data $data) public function collect(Request $request, Response $response, \Exception $exception = null) { // Sub-requests and programmatic calls stay in the collected profile. - if (($this->requestStack && $this->requestStack->getMasterRequest() !== $request) || $request->isXmlHttpRequest() || $request->headers->has('Origin')) { + if ($this->dumper || ($this->requestStack && $this->requestStack->getMasterRequest() !== $request) || $request->isXmlHttpRequest() || $request->headers->has('Origin')) { return; } @@ -154,13 +154,9 @@ public function collect(Request $request, Response $response, \Exception $except $this->dumper = new CliDumper('php://output', $this->charset); } - foreach ($this->data as $i => $dump) { - $this->data[$i] = null; + foreach ($this->data as $dump) { $this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']); } - - $this->data = array(); - $this->dataCount = 0; } } diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php index 7d19cb01b1d8c..5869c72500d53 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php @@ -72,6 +72,8 @@ public function testCollectDefault() $output = ob_get_clean(); $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output); + $this->assertSame(1, $collector->getDumpsCount()); + $collector->serialize(); } public function testCollectHtml() @@ -99,6 +101,8 @@ public function testCollectHtml() $output = preg_replace('/sf-dump-\d+/', 'sf-dump', $output); $this->assertSame($xOutput, $output); + $this->assertSame(1, $collector->getDumpsCount()); + $collector->serialize(); } public function testFlush() From 5368483d9a4a0655afdb1169cd6655f3b1d76172 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 May 2015 09:57:59 +0200 Subject: [PATCH 2/3] [DebugBundle] Use output mechanism of dumpers instead of echoing --- .../DataCollector/DumpDataCollector.php | 35 +++++++++++++------ .../DataCollector/DumpDataCollectorTest.php | 27 +++++++++++--- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index c4101e2d62919..74faed19ee46c 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -246,20 +246,33 @@ public function __destruct() private function doDump($data, $name, $file, $line) { - if ($this->dumper instanceof HtmlDumper) { - $name = $this->htmlEncode($name); - $file = $this->htmlEncode($file); - if ('' !== $file) { - if ($this->fileLinkFormat) { - $link = strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line)); - $name = sprintf('%s', $link, $file, $name); + if (PHP_VERSION_ID >= 50400 && $this->dumper instanceof CliDumper) { + $contextDumper = function ($name, $file, $line, $fileLinkFormat) { + if ($this instanceof HtmlDumper) { + if ('' !== $file) { + $s = $this->style('meta', '%s'); + $name = strip_tags($this->style('', $name)); + $file = strip_tags($this->style('', $file)); + if ($fileLinkFormat) { + $link = strtr($fileLinkFormat, array('%f' => $file, '%l' => (int) $line)); + $name = sprintf(''.$s.'', $link, $file, $name); + } else { + $name = sprintf(''.$s.'', $file, $name); + } + } else { + $name = $this->style('meta', $name); + } + $this->line = $name.' on line '.$this->style('meta', $line).':'; } else { - $name = sprintf('%s', $file, $name); + $this->line = $this->style('meta', $name).' on line '.$this->style('meta', $line).':'; } - } - echo "\n{$name} on line {$line}:"; + $this->dumpLine(0); + }; + $contextDumper = $contextDumper->bindTo($this->dumper, $this->dumper); + $contextDumper($name, $file, $line, $this->fileLinkFormat); } else { - echo "{$name} on line {$line}:\n"; + $cloner = new VarCloner(); + $this->dumper->dump($cloner->cloneVar($name.' on line '.$line.':')); } $this->dumper->dump($data); } diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php index 5869c72500d53..e9b8433c46ef5 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php @@ -71,7 +71,11 @@ public function testCollectDefault() $collector->collect(new Request(), new Response()); $output = ob_get_clean(); - $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output); + if (PHP_VERSION_ID >= 50400) { + $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output); + } else { + $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n123\n", $output); + } $this->assertSame(1, $collector->getDumpsCount()); $collector->serialize(); } @@ -85,12 +89,23 @@ public function testCollectHtml() $collector->dump($data); $line = __LINE__ - 1; $file = __FILE__; - $xOutput = <<= 50400) { + $xOutput = <<DumpDataCollectorTest.php on line {$line}: +123 + -DumpDataCollectorTest.php on line {$line}:
123
+EOTXT;
+        } else {
+            $len = strlen("DumpDataCollectorTest.php on line {$line}:");
+            $xOutput = <<"DumpDataCollectorTest.php on line {$line}:"
+
+
123
 
EOTXT; + } ob_start(); $response = new Response(); @@ -114,6 +129,10 @@ public function testFlush() ob_start(); $collector = null; - $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean()); + if (PHP_VERSION_ID >= 50400) { + $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean()); + } else { + $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean()); + } } } From 5f255e505936824edacdcbe6d4268848b0e54bad Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 May 2015 15:58:04 +0200 Subject: [PATCH 3/3] [DebugBundle] Allow alternative destination for dumps --- src/Symfony/Bundle/DebugBundle/DebugBundle.php | 3 +-- .../DebugBundle/DependencyInjection/Configuration.php | 5 +++++ .../DebugBundle/DependencyInjection/DebugExtension.php | 10 ++++++++++ .../Bundle/DebugBundle/Resources/config/services.xml | 5 +++++ .../HttpKernel/DataCollector/DumpDataCollector.php | 9 +++++++-- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/DebugBundle/DebugBundle.php b/src/Symfony/Bundle/DebugBundle/DebugBundle.php index fdd7724dfc1de..3aa536dba7860 100644 --- a/src/Symfony/Bundle/DebugBundle/DebugBundle.php +++ b/src/Symfony/Bundle/DebugBundle/DebugBundle.php @@ -14,7 +14,6 @@ use Symfony\Bundle\DebugBundle\DependencyInjection\Compiler\DumpDataCollectorPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\VarDumper; /** @@ -31,7 +30,7 @@ public function boot() // configuration for CLI mode is overridden in HTTP mode on // 'kernel.request' event VarDumper::setHandler(function ($var) use ($container) { - $dumper = new CliDumper(); + $dumper = $container->get('var_dumper.cli_dumper'); $cloner = $container->get('var_dumper.cloner'); $handler = function ($var) use ($dumper, $cloner) { $dumper->dump($cloner->cloneVar($var)); diff --git a/src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php index 52cdfa94fe762..5761e62a72e1a 100644 --- a/src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php @@ -41,6 +41,11 @@ public function getConfigTreeBuilder() ->min(-1) ->defaultValue(-1) ->end() + ->scalarNode('dump_destination') + ->info('A stream URL where dumps should be written to') + ->example('php://stderr') + ->defaultNull() + ->end() ->end() ; diff --git a/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php b/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php index d5c4fd93d1fae..4e5351c0e0cda 100644 --- a/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php +++ b/src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php @@ -14,6 +14,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** @@ -37,6 +38,15 @@ public function load(array $configs, ContainerBuilder $container) $container->getDefinition('var_dumper.cloner') ->addMethodCall('setMaxItems', array($config['max_items'])) ->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')) + ; + } } /** diff --git a/src/Symfony/Bundle/DebugBundle/Resources/config/services.xml b/src/Symfony/Bundle/DebugBundle/Resources/config/services.xml index 7de182861b434..16e27a22c584d 100644 --- a/src/Symfony/Bundle/DebugBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/DebugBundle/Resources/config/services.xml @@ -16,6 +16,7 @@ null %kernel.charset% + null @@ -25,6 +26,10 @@ + + null + %kernel.charset% + diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index 74faed19ee46c..32b99e562c5a4 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -35,13 +35,16 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface private $rootRefs; private $charset; 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->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; + $this->dumper = $dumper; + $this->dumperIsInjected = null !== $dumper; // All clones share these properties by reference: $this->rootRefs = array( @@ -170,7 +173,9 @@ public function serialize() $this->data = array(); $this->dataCount = 0; $this->isCollected = true; - $this->dumper = null; + if (!$this->dumperIsInjected) { + $this->dumper = null; + } return $ser; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy