4 * This file is part of Twig.
6 * (c) 2010 Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * Represents a debug node.
16 * @subpackage Twig-extensions
17 * @author Fabien Potencier <fabien.potencier@symfony-project.com>
20 class Twig_Extensions_Node_Debug
extends Twig_Node
22 public function __construct(Twig_Node_Expression
$expr = null, $lineno, $tag = null)
24 parent
::__construct(array('expr' => $expr), array(), $lineno, $tag);
28 * Compiles the node to PHP.
30 * @param Twig_Compiler A Twig_Compiler instance
32 public function compile(Twig_Compiler
$compiler)
34 $compiler->addDebugInfo($this);
37 ->write("if (\$this->env->isDebug()) {\n")
41 if (null === $this->getNode('expr')) {
42 // remove embedded templates (macros) from the context
44 ->write("\$vars = array();\n")
45 ->write("foreach (\$context as \$key => \$value) {\n")
47 ->write("if (!\$value instanceof Twig_Template) {\n")
49 ->write("\$vars[\$key] = \$value;\n")
54 ->write("var_dump(\$vars);\n")
59 ->subcompile($this->getNode('expr'))