[DebugBundle] adjust after review
This commit is contained in:
parent
eb98c81754
commit
8d5d970eea
|
@ -87,7 +87,7 @@
|
|||
],
|
||||
"files": [
|
||||
"src/Symfony/Component/Intl/Resources/stubs/functions.php",
|
||||
"src/Symfony/Bundle/DebugBundle/Resources/functions/dump.php"
|
||||
"src/Symfony/Component/VarDumper/Resources/functions/dump.php"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
|
|
|
@ -16,9 +16,12 @@ namespace Symfony\Bridge\Twig\Node;
|
|||
*/
|
||||
class DumpNode extends \Twig_Node
|
||||
{
|
||||
public function __construct(\Twig_NodeInterface $values = null, $lineno, $tag = null)
|
||||
private $varPrefix;
|
||||
|
||||
public function __construct($varPrefix, \Twig_NodeInterface $values = null, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(array('values' => $values), array(), $lineno, $tag);
|
||||
$this->varPrefix = $varPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,30 +39,30 @@ class DumpNode extends \Twig_Node
|
|||
if (null === $values) {
|
||||
// remove embedded templates (macros) from the context
|
||||
$compiler
|
||||
->write("\$vars = array();\n")
|
||||
->write("foreach (\$context as \$key => \$value) {\n")
|
||||
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
|
||||
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
|
||||
->indent()
|
||||
->write("if (!\$value instanceof Twig_Template) {\n")
|
||||
->write(sprintf('if (!$%sval instanceof \Twig_Template) {'."\n", $this->varPrefix))
|
||||
->indent()
|
||||
->write("\$vars[\$key] = \$value;\n")
|
||||
->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $this->varPrefix))
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->addDebugInfo($this)
|
||||
->write('\Symfony\Component\Debug\Debug::dump($vars);'."\n")
|
||||
->write(sprintf('\Symfony\Component\VarDumper\VarDumper::dump($%svars);'."\n", $this->varPrefix))
|
||||
;
|
||||
} elseif (1 === $values->count()) {
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write('\Symfony\Component\Debug\Debug::dump(')
|
||||
->write('\Symfony\Component\VarDumper\VarDumper::dump(')
|
||||
->subcompile($values->getNode(0))
|
||||
->raw(");\n")
|
||||
;
|
||||
} else {
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write('\Symfony\Component\Debug\Debug::dump(array(')
|
||||
->write('\Symfony\Component\VarDumper\VarDumper::dump(array(')
|
||||
->indent()
|
||||
;
|
||||
foreach ($values as $node) {
|
||||
|
|
|
@ -38,7 +38,7 @@ class DumpTokenParser extends \Twig_TokenParser
|
|||
}
|
||||
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new DumpNode($values, $token->getLine(), $this->getTag());
|
||||
return new DumpNode($this->parser->getVarName(), $values, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
<parameters>
|
||||
<parameter key="debug.templating.engine.twig.class">Symfony\Bundle\TwigBundle\Debug\TimedTwigEngine</parameter>
|
||||
<parameter key="twig.extension.dump.class">Symfony\Bridge\Twig\Extension\DumpExtension</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
|
@ -19,5 +20,9 @@
|
|||
<service id="twig.extension.debug" class="Twig_Extension_Debug" public="false">
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.dump" class="%twig.extension.dump.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
|
@ -11,11 +11,6 @@
|
|||
|
||||
namespace Symfony\Component\Debug;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\ExtCloner;
|
||||
use Symfony\Component\VarDumper\Cloner\PhpCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||
|
||||
/**
|
||||
* Registers all the debug tools.
|
||||
*
|
||||
|
@ -24,7 +19,6 @@ use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
|||
class Debug
|
||||
{
|
||||
private static $enabled = false;
|
||||
private static $dumpHandler;
|
||||
|
||||
/**
|
||||
* Enables the debug tools.
|
||||
|
@ -65,42 +59,4 @@ class Debug
|
|||
|
||||
DebugClassLoader::enable();
|
||||
}
|
||||
|
||||
public static function dump($var)
|
||||
{
|
||||
if (null === self::$dumpHandler) {
|
||||
$cloner = extension_loaded('symfony_debug') ? new ExtCloner() : new PhpCloner();
|
||||
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
|
||||
self::$dumpHandler = function ($var) use ($cloner, $dumper) {
|
||||
$dumper->dump($cloner->cloneVar($var));
|
||||
};
|
||||
}
|
||||
|
||||
$h = self::$dumpHandler;
|
||||
|
||||
if (is_array($h)) {
|
||||
return $h[0]->{$h[1]}($var);
|
||||
}
|
||||
|
||||
return $h($var);
|
||||
}
|
||||
|
||||
public static function setDumpHandler($callable)
|
||||
{
|
||||
if (!is_callable($callable)) {
|
||||
throw new \InvalidArgumentException('Invalid PHP callback.');
|
||||
}
|
||||
|
||||
$prevHandler = self::$dumpHandler;
|
||||
|
||||
if (is_array($callable)) {
|
||||
if (!is_object($callable[0])) {
|
||||
self::$dumpHandler = $callable[0].'::'.$callable[1];
|
||||
}
|
||||
} else {
|
||||
self::$dumpHandler = $callable;
|
||||
}
|
||||
|
||||
return $prevHandler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@
|
|||
"psr/log": "~1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "~2.6",
|
||||
"symfony/http-kernel": "~2.1",
|
||||
"symfony/http-foundation": "~2.1"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/var-dumper": "For using Debug::dump()",
|
||||
"symfony/http-foundation": "",
|
||||
"symfony/http-kernel": ""
|
||||
},
|
||||
|
|
|
@ -64,10 +64,10 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
|||
$name = false;
|
||||
$fileExcerpt = false;
|
||||
|
||||
for ($i = 1; $i < 6; ++$i) {
|
||||
for ($i = 1; $i < 7; ++$i) {
|
||||
if (isset($trace[$i]['class'], $trace[$i]['function'])
|
||||
&& 'dump' === $trace[$i]['function']
|
||||
&& 'Symfony\Bundle\DebugBundle\DebugBundle' === $trace[$i]['class']
|
||||
&& 'Symfony\Component\VarDumper\VarDumper' === $trace[$i]['class']
|
||||
) {
|
||||
$file = $trace[$i]['file'];
|
||||
$line = $trace[$i]['line'];
|
||||
|
|
|
@ -68,6 +68,8 @@ class DOMCaster
|
|||
|
||||
public static function castNode(\DOMNode $dom, array $a, $isNested, &$cut)
|
||||
{
|
||||
// Commented lines denote properties that exist but are better not dumped for clarity.
|
||||
|
||||
$a += array(
|
||||
'nodeName' => $dom->nodeName,
|
||||
//'nodeValue' => $dom->nodeValue,
|
||||
|
@ -93,6 +95,8 @@ class DOMCaster
|
|||
|
||||
public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, $isNested, &$cut)
|
||||
{
|
||||
// Commented lines denote properties that exist but are better not dumped for clarity.
|
||||
|
||||
$a += array(
|
||||
'nodeName' => $dom->nodeName,
|
||||
//'nodeValue' => $dom->nodeValue,
|
||||
|
|
|
@ -183,7 +183,8 @@ class Data
|
|||
{
|
||||
if (function_exists('iconv')) {
|
||||
return iconv('CP1252', 'UTF-8', $s);
|
||||
} else {
|
||||
}
|
||||
|
||||
$s .= $s;
|
||||
$len = strlen($s);
|
||||
|
||||
|
@ -198,4 +199,3 @@ class Data
|
|||
return substr($s, 0, $j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
|
||||
if (!function_exists('dump')) {
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
function dump($var)
|
||||
{
|
||||
foreach (func_get_args() as $var) {
|
||||
VarDumper::dump($var);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\ExtCloner;
|
||||
use Symfony\Component\VarDumper\Cloner\PhpCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class VarDumper
|
||||
{
|
||||
private static $handler;
|
||||
|
||||
public static function dump($var)
|
||||
{
|
||||
if (null === self::$handler) {
|
||||
$cloner = extension_loaded('symfony_debug') ? new ExtCloner() : new PhpCloner();
|
||||
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
|
||||
self::$handler = function ($var) use ($cloner, $dumper) {
|
||||
$dumper->dump($cloner->cloneVar($var));
|
||||
};
|
||||
}
|
||||
|
||||
return call_user_func(self::$handler, $h);
|
||||
}
|
||||
|
||||
public static function setHandler($callable)
|
||||
{
|
||||
if (!is_callable($callable, true)) {
|
||||
throw new \InvalidArgumentException('Invalid PHP callback.');
|
||||
}
|
||||
|
||||
$prevHandler = self::$handler;
|
||||
self::$handler = $callable;
|
||||
|
||||
return $prevHandler;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@
|
|||
"ext-symfony_debug": ""
|
||||
},
|
||||
"autoload": {
|
||||
"files": [ "Resources/functions/dump.php" ],
|
||||
"psr-0": { "Symfony\\Component\\VarDumper\\": "" }
|
||||
},
|
||||
"target-dir": "Symfony/Component/VarDumper",
|
||||
|
|
Reference in New Issue