]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/lib/Twig/Node/Macro.php
4 * This file is part of Twig.
6 * (c) 2009 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 macro node.
15 * @author Fabien Potencier <fabien@symfony.com>
17 class Twig_Node_Macro
extends Twig_Node
19 public function __construct($name, Twig_NodeInterface
$body, Twig_NodeInterface
$arguments, $lineno, $tag = null)
21 parent
::__construct(array('body' => $body, 'arguments' => $arguments), array('name' => $name), $lineno, $tag);
25 * Compiles the node to PHP.
27 * @param Twig_Compiler A Twig_Compiler instance
29 public function compile(Twig_Compiler
$compiler)
33 ->write(sprintf("public function get%s(", $this->getAttribute('name')))
36 $count = count($this->getNode('arguments'));
38 foreach ($this->getNode('arguments') as $name => $default) {
40 ->raw('$_'.$name.' = ')
41 ->subcompile($default)
44 if (++$pos < $count) {
55 if (!count($this->getNode('arguments
'))) {
56 $compiler->write("\$context = \$this->env->getGlobals();\n\n");
59 ->write("\$context = \$this->env->mergeGlobals(array(\n")
63 foreach ($this->getNode('arguments
') as $name => $default) {
79 ->write("\$blocks = array();\n\n")
80 ->write("ob_start();\n")
83 ->subcompile($this->getNode('body'))
85 ->write("} catch (Exception \$e) {\n")
87 ->write("ob_end_clean();\n\n")
88 ->write("throw \$e;\n")
91 ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")