From ad052d8ed2c5e71f8f268f71c8c31f74d0b738d9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 28 Jun 2010 12:36:53 +0200 Subject: [PATCH] removed Twig_Template instances from the debug tag output (closes #73) --- CHANGELOG | 1 + lib/Twig/Node/Debug.php | 23 +++++++++++++++++++---- test/Twig/Tests/Node/DebugTest.php | 10 ++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 20ced20..300514e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 0.9.8 + * removed Twig_Template instances from the debug tag output * fixed objects with __isset() defined * fixed set tag when used with a capture * fixed type hinting for Twig_Environment::addFilter() method diff --git a/lib/Twig/Node/Debug.php b/lib/Twig/Node/Debug.php index 1832c7d..7f46b53 100644 --- a/lib/Twig/Node/Debug.php +++ b/lib/Twig/Node/Debug.php @@ -35,17 +35,32 @@ class Twig_Node_Debug extends Twig_Node $compiler ->write("if (\$this->env->isDebug()) {\n") ->indent() - ->write('var_export(') ; if (null === $this->expr) { - $compiler->raw('$context'); + // remove embedded templates (macros) from the context + $compiler + ->write("\$vars = array();\n") + ->write("foreach (\$context as \$key => \$value) {\n") + ->indent() + ->write("if (!\$value instanceof Twig_Template) {\n") + ->indent() + ->write("\$vars[\$key] = \$value;\n") + ->outdent() + ->write("}\n") + ->outdent() + ->write("}\n") + ->write("print_r(\$vars);\n") + ; } else { - $compiler->subcompile($this->expr); + $compiler + ->write("print_r(") + ->subcompile($this->expr) + ->raw(");\n") + ; } $compiler - ->raw(");\n") ->outdent() ->write("}\n") ; diff --git a/test/Twig/Tests/Node/DebugTest.php b/test/Twig/Tests/Node/DebugTest.php index 1e1e14b..f67c593 100644 --- a/test/Twig/Tests/Node/DebugTest.php +++ b/test/Twig/Tests/Node/DebugTest.php @@ -41,7 +41,13 @@ class Twig_Tests_Node_DebugTest extends Twig_Tests_Node_TestCase $tests[] = array(new Twig_Node_Debug(null, 0), <<env->isDebug()) { - var_export(\$context); + \$vars = array(); + foreach (\$context as \$key => \$value) { + if (!\$value instanceof Twig_Template) { + \$vars[\$key] = \$value; + } + } + print_r(\$vars); } EOF ); @@ -51,7 +57,7 @@ EOF $tests[] = array($node, <<env->isDebug()) { - var_export((isset(\$context['foo']) ? \$context['foo'] : null)); + print_r((isset(\$context['foo']) ? \$context['foo'] : null)); } EOF ); -- 1.7.2.5