diff options
Diffstat (limited to 'inc/Twig/Extensions/Node/Debug.php')
-rw-r--r-- | inc/Twig/Extensions/Node/Debug.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/inc/Twig/Extensions/Node/Debug.php b/inc/Twig/Extensions/Node/Debug.php new file mode 100644 index 00000000..7d01bbe5 --- /dev/null +++ b/inc/Twig/Extensions/Node/Debug.php | |||
@@ -0,0 +1,69 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of Twig. | ||
5 | * | ||
6 | * (c) 2010 Fabien Potencier | ||
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 | /** | ||
13 | * Represents a debug node. | ||
14 | * | ||
15 | * @package twig | ||
16 | * @subpackage Twig-extensions | ||
17 | * @author Fabien Potencier <fabien.potencier@symfony-project.com> | ||
18 | * @version SVN: $Id$ | ||
19 | */ | ||
20 | class Twig_Extensions_Node_Debug extends Twig_Node | ||
21 | { | ||
22 | public function __construct(Twig_Node_Expression $expr = null, $lineno, $tag = null) | ||
23 | { | ||
24 | parent::__construct(array('expr' => $expr), array(), $lineno, $tag); | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * Compiles the node to PHP. | ||
29 | * | ||
30 | * @param Twig_Compiler A Twig_Compiler instance | ||
31 | */ | ||
32 | public function compile(Twig_Compiler $compiler) | ||
33 | { | ||
34 | $compiler->addDebugInfo($this); | ||
35 | |||
36 | $compiler | ||
37 | ->write("if (\$this->env->isDebug()) {\n") | ||
38 | ->indent() | ||
39 | ; | ||
40 | |||
41 | if (null === $this->getNode('expr')) { | ||
42 | // remove embedded templates (macros) from the context | ||
43 | $compiler | ||
44 | ->write("\$vars = array();\n") | ||
45 | ->write("foreach (\$context as \$key => \$value) {\n") | ||
46 | ->indent() | ||
47 | ->write("if (!\$value instanceof Twig_Template) {\n") | ||
48 | ->indent() | ||
49 | ->write("\$vars[\$key] = \$value;\n") | ||
50 | ->outdent() | ||
51 | ->write("}\n") | ||
52 | ->outdent() | ||
53 | ->write("}\n") | ||
54 | ->write("var_dump(\$vars);\n") | ||
55 | ; | ||
56 | } else { | ||
57 | $compiler | ||
58 | ->write("var_dump(") | ||
59 | ->subcompile($this->getNode('expr')) | ||
60 | ->raw(");\n") | ||
61 | ; | ||
62 | } | ||
63 | |||
64 | $compiler | ||
65 | ->outdent() | ||
66 | ->write("}\n") | ||
67 | ; | ||
68 | } | ||
69 | } | ||