8000 [DebugBundle] adjust after review · symfony/symfony@8d5d970 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d5d970

Browse files
[DebugBundle] adjust after review
1 parent eb98c81 commit 8d5d970

File tree

12 files changed

+111
-70
lines changed

12 files changed

+111
-70
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
],
8888
"files": [
8989
"src/Symfony/Component/Intl/Resources/stubs/functions.php",
90-
"src/Symfony/Bundle/DebugBundle/Resources/functions/dump.php"
90+
"src/Symfony/Component/VarDumper/Resources/functions/dump.php"
9191
]
9292
},
9393
"minimum-stability": "dev",

src/Symfony/Bridge/Twig/Node/DumpNode.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
*/
1717
class DumpNode extends \Twig_Node
1818
{
19-
public function __construct(\Twig_NodeInterface $values = null, $lineno, $tag = null)
19+
private $varPrefix;
20+
21+
public function __construct($varPrefix, \Twig_NodeInterface $values = null, $lineno, $tag = null)
2022
{
2123
parent::__construct(array('values' => $values), array(), $lineno, $tag);
24+
$this->varPrefix = $varPrefix;
2225
}
2326

2427
/**
@@ -36,30 +39,30 @@ public function compile(\Twig_Compiler $compiler)
3639
if (null === $values) {
3740
// remove embedded templates (macros) from the context
3841
$compiler
39-
->write("\$vars = array();\n")
40-
->write("foreach (\$context as \$key => \$value) {\n")
42+
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
43+
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
4144
->indent()
42-
->write("if (!\$value instanceof Twig_Template) {\n")
45+
->write(sprintf('if (!$%sval instanceof \Twig_Template) {'."\n", $this->varPrefix))
4346
->indent()
44-
->write("\$vars[\$key] = \$value;\n")
47+
->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $this->varPrefix))
4548
->outdent()
4649
->write("}\n")
4750
->outdent()
4851
->write("}\n")
4952
->addDebugInfo($this)
50-
->write('\Symfony\Component\Debug\Debug::dump($vars);'."\n")
53+
->write(sprintf('\Symfony\Component\VarDumper\VarDumper::dump($%svars);'."\n", $this->varPrefix))
5154
;
5255
} elseif (1 === $values->count()) {
5356
$compiler
5457
->addDebugInfo($this)
55-
->write('\Symfony\Component\Debug\Debug::dump(')
58+
->write('\Symfony\Component\VarDumper\VarDumper::dump(')
5659
->subcompile($values->getNode(0))
5760
->raw(");\n")
5861
;
5962
} else {
6063
$compiler
6164
->addDebugInfo($this)
62-
->write('\Symfony\Component\Debug\Debug::dump(array(')
65+
->write('\Symfony\Component\VarDumper\VarDumper::dump(array(')
6366
->indent()
6467
;
6568
foreach ($values as $node) {

src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function parse(\Twig_Token $token)
3838
}
3939
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
4040

41-
return new DumpNode($values, $token->getLine(), $this->getTag());
41+
return new DumpNode($this->parser->getVarName(), $values, $token->getLine(), $this->getTag());
4242
}
4343

4444
/**

src/Symfony/Bundle/TwigBundle/Resources/config/debug.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<parameters>
88
<parameter key="debug.templating.engine.twig.class">Symfony\Bundle\TwigBundle\Debug\TimedTwigEngine</parameter>
9+
<parameter key="twig.extension.dump.class">Symfony\Bridge\Twig\Extension\DumpExtension</parameter>
910
</parameters>
1011

1112
<services>
@@ -19,5 +20,9 @@
1920
<service id="twig.extension.debug" class="Twig_Extension_Debug" public="false">
2021
<tag name="twig.extension" />
2122
</service>
23+
24+
<service id="twig.extension.dump" class="%twig.extension.dump.class%" public="false">
25+
<tag name="twig.extension" />
26+
</service>
2227
</services>
2328
</container>

src/Symfony/Component/Debug/Debug.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111

1212
namespace Symfony\Component\Debug;
1313

14-
use Symfony\Component\VarDumper\Cloner\ExtCloner;
15-
use Symfony\Component\VarDumper\Cloner\PhpCloner;
16-
use Symfony\Component\VarDumper\Dumper\CliDumper;
17-
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
18-
1914
/**
2015
* Registers all the debug tools.
2116
*
@@ -24,7 +19,6 @@
2419
class Debug
2520
{
2621
private static $enabled = false;
27-
private static $dumpHandler;
2822

2923
/**
3024
* Enables the debug tools.
@@ -65,42 +59,4 @@ public static function enable($errorReportingLevel = null, $displayErrors = true
6559

6660
DebugClassLoader::enable();
6761
}
68-
69-
public static function dump($var)
70-
{
71-
if (null === self::$dumpHandler) {
72-
$cloner = extension_loaded('symfony_debug') ? new ExtCloner() : new PhpCloner();
73-
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
74-
self::$dumpHandler = function ($var) use ($cloner, $dumper) {
75-
$dumper->dump($cloner->cloneVar($var));
76-
};
77-
}
78-
79-
$h = self::$dumpHandler;
80-
81-
if (is_array($h)) {
82-
return $h[0]->{$h[1]}($var);
83-
}
84-
85-
return $h($var);
86-
}
87-
88-
public static function setDumpHandler($callable)
89-
{
90-
if (!is_callable($callable)) {
91-
throw new \InvalidArgumentException('Invalid PHP callback.');
92-
}
93-
94-
$prevHandler = self::$dumpHandler;
95-
96-
if (is_array($callable)) {
97-
if (!is_object($callable[0])) {
98-
self::$dumpHandler = $callable[0].'::'.$callable[1];
99-
}
100-
} else {
101-
self::$dumpHandler = $callable;
102-
}
103-
104-
return $prevHandler;
105-
}
10662
}

src/Symfony/Component/Debug/composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
"psr/log": "~1.0"
2121
},
2222
"require-dev": {
23-
"symfony/var-dumper": "~2.6",
2423
"symfony/http-kernel": "~2.1",
2524
"symfony/http-foundation": "~2.1"
2625
},
2726
"suggest": {
28-
"symfony/var-dumper": "For using Debug::dump()",
2927
"symfony/http-foundation": "",
3028
"symfony/http-kernel": ""
3129
},

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public function dump(Data $data)
6464
$name = false;
6565
$fileExcerpt = false;
6666

67-
for ($i = 1; $i < 6; ++$i) {
67+
for ($i = 1; $i < 7; ++$i) {
6868
if (isset($trace[$i]['class'], $trace[$i]['function'])
6969
&& 'dump' === $trace[$i]['function']
70-
&& 'Symfony\Bundle\DebugBundle\DebugBundle' === $trace[$i]['class']
70+
&& 'Symfony\Component\VarDumper\VarDumper' === $trace[$i]['class']
7171
) {
7272
$file = $trace[$i]['file'];
7373
$line = $trace[$i]['line'];

src/Symfony/Component/VarDumper/Caster/DOMCaster.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public static function castImplementation($dom, array $a, $isNested, &$cut)
6868

6969
public static function castNode(\DOMNode $dom, array $a, $isNested, &$cut)
7070
{
71+
// Commented lines denote properties that exist but are better not dumped for clarity.
72+
7173
$a += array(
7274
'nodeName' => $dom->nodeName,
7375
//'nodeValue' => $dom->nodeValue,
@@ -93,6 +95,8 @@ public static function castNode(\DOMNode $dom, array $a, $isNested, &$cut)
9395

9496
public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, $isNested, &$cut)
9597
{
98+
// Commented lines denote properties that exist but are better not dumped for clarity.
99+
96100
$a += array(
97101
'nodeName' => $dom->nodeName,
98102
//'nodeValue' => $dom->nodeValue,

src/Symfony/Component/VarDumper/Cloner/Data.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,19 @@ public static function utf8Encode($s)
183183
{
184184
if (function_exists('iconv')) {
185185
return iconv('CP1252', 'UTF-8', $s);
186-
} else {
187-
$s .= $s;
188-
$len = strlen($s);
189-
190-
for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
191-
switch (true) {
192-
case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
193-
case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
194-
default: $s[$j] = "\xC3"; $s[++$j] = chr(ord($s[$i]) - 64); break;
195-
}
196-
}
186+
}
197187

198-
return substr($s, 0, $j);
188+
$s .= $s;
189+
$len = strlen($s);
190+
191+
for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
192+
switch (true) {
193+
case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
194+
case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
195+
default: $s[$j] = "\xC3"; $s[++$j] = chr(ord($s[$i]) - 64); break;
196+
}
199197
}
198+
199+
return substr($s, 0, $j);
200200
}
201201
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Component\VarDumper\VarDumper;
13+
14+
if (!function_exists('dump')) {
15+
/**
16+
* @author Nicolas Grekas <p@tchwork.com>
17+
*/
18+
function dump($var)
19+
{
20+
foreach (func_get_args() as $var) {
21+
VarDumper::dump($var);
22+
}
23+
}
24+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper;
13+
14+
use Symfony\Component\VarDumper\Cloner\ExtCloner;
15+
use Symfony\Component\VarDumper\Cloner\PhpCloner;
16+
use Symfony\Component\VarDumper\Dumper\CliDumper;
17+
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
18+
19+
/**
20+
* @author Nicolas Grekas <p@tchwork.com>
21+
*/
22+
class VarDumper
23+
{
24+
private static $handler;
25+
26+
public static function dump($var)
27+
{
28+
if (null === self::$handler) {
29+
$cloner = extension_loaded('symfony_debug') ? new ExtCloner() : new PhpCloner();
30+
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
31+
self::$handler = function ($var) use ($cloner, $dumper) {
32+
$dumper->dump($cloner->cloneVar($var));
33+
};
34+
}
35+
36+
return call_user_func(self::$handler, $h);
37+
}
38+
39+
public static function setHandler($callable)
40+
{
41+
if (!is_callable($callable, true)) {
42+
throw new \InvalidArgumentException('Invalid PHP callback.');
43+
}
44+
45+
$prevHandler = self::$handler;
46+
self::$handler = $callable;
47+
48+
return $prevHandler;
49+
}
50+
}

src/Symfony/Component/VarDumper/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"ext-symfony_debug": ""
1919
},
2020
"autoload": {
21+
"files": [ "Resources/functions/dump.php" ],
2122
"psr-0": { "Symfony\\Component\\VarDumper\\": "" }
2223
},
2324
"target-dir": "Symfony/Component/VarDumper",

0 commit comments

Comments
 (0)
0