]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/Twig/Node/Set.php
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 set node.
15 * @author Fabien Potencier <fabien@symfony.com>
17 class Twig_Node_Set
extends Twig_Node
19 public function __construct($capture, Twig_NodeInterface
$names, Twig_NodeInterface
$values, $lineno, $tag = null)
21 parent
::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag);
24 * Optimizes the node when capture is used for a large block of text.
26 * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo");
28 if ($this->getAttribute('capture')) {
29 $this->setAttribute('safe', true);
31 $values = $this->getNode('values');
32 if ($values instanceof Twig_Node_Text
) {
33 $this->setNode('values', new Twig_Node_Expression_Constant($values->getAttribute('data'), $values->getLine()));
34 $this->setAttribute('capture', false);
40 * Compiles the node to PHP.
42 * @param Twig_Compiler A Twig_Compiler instance
44 public function compile(Twig_Compiler
$compiler)
46 $compiler->addDebugInfo($this);
48 if (count($this->getNode('names')) > 1) {
49 $compiler->write('list(');
50 foreach ($this->getNode('names') as $idx => $node) {
55 $compiler->subcompile($node);
59 if ($this->getAttribute('capture')) {
61 ->write("ob_start();\n")
62 ->subcompile($this->getNode('values'))
66 $compiler->subcompile($this->getNode('names'), false);
68 if ($this->getAttribute('capture')) {
69 $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())");
73 if (!$this->getAttribute('capture')) {
74 $compiler->raw(' = ');
76 if (count($this->getNode('names')) > 1) {
77 $compiler->write('array(');
78 foreach ($this->getNode('values') as $idx => $value) {
83 $compiler->subcompile($value);
87 if ($this->getAttribute('safe')) {
89 ->raw("('' === \$tmp = ")
90 ->subcompile($this->getNode('values'))
91 ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())")
94 $compiler->subcompile($this->getNode('values'));
99 $compiler->raw(";\n");