From 8069e235fd2971675ee5fc05026ffa9bce5cbbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Aug 2013 22:43:56 +0200 Subject: move Twig in 3rdparty --- inc/3rdparty/Twig/Extensions/Node/Debug.php | 69 +++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 inc/3rdparty/Twig/Extensions/Node/Debug.php (limited to 'inc/3rdparty/Twig/Extensions/Node/Debug.php') diff --git a/inc/3rdparty/Twig/Extensions/Node/Debug.php b/inc/3rdparty/Twig/Extensions/Node/Debug.php new file mode 100644 index 00000000..7d01bbe5 --- /dev/null +++ b/inc/3rdparty/Twig/Extensions/Node/Debug.php @@ -0,0 +1,69 @@ + + * @version SVN: $Id$ + */ +class Twig_Extensions_Node_Debug extends Twig_Node +{ + public function __construct(Twig_Node_Expression $expr = null, $lineno, $tag = null) + { + parent::__construct(array('expr' => $expr), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler->addDebugInfo($this); + + $compiler + ->write("if (\$this->env->isDebug()) {\n") + ->indent() + ; + + if (null === $this->getNode('expr')) { + // 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("var_dump(\$vars);\n") + ; + } else { + $compiler + ->write("var_dump(") + ->subcompile($this->getNode('expr')) + ->raw(");\n") + ; + } + + $compiler + ->outdent() + ->write("}\n") + ; + } +} -- cgit v1.2.3