PEEL Shopping
Open source ecommerce : PEEL Shopping
Set.php
Go to the documentation of this file.
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 
17 class Twig_Node_Set extends Twig_Node
18 {
19  public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null)
20  {
21  parent::__construct(array('names' => $names, 'values' => $values), array('capture' => $capture, 'safe' => false), $lineno, $tag);
22 
23  /*
24  * Optimizes the node when capture is used for a large block of text.
25  *
26  * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig_Markup("foo");
27  */
28  if ($this->getAttribute('capture')) {
29  $this->setAttribute('safe', true);
30 
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);
35  }
36  }
37  }
38 
44  public function compile(Twig_Compiler $compiler)
45  {
46  $compiler->addDebugInfo($this);
47 
48  if (count($this->getNode('names')) > 1) {
49  $compiler->write('list(');
50  foreach ($this->getNode('names') as $idx => $node) {
51  if ($idx) {
52  $compiler->raw(', ');
53  }
54 
55  $compiler->subcompile($node);
56  }
57  $compiler->raw(')');
58  } else {
59  if ($this->getAttribute('capture')) {
60  $compiler
61  ->write("ob_start();\n")
62  ->subcompile($this->getNode('values'))
63  ;
64  }
65 
66  $compiler->subcompile($this->getNode('names'), false);
67 
68  if ($this->getAttribute('capture')) {
69  $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())");
70  }
71  }
72 
73  if (!$this->getAttribute('capture')) {
74  $compiler->raw(' = ');
75 
76  if (count($this->getNode('names')) > 1) {
77  $compiler->write('array(');
78  foreach ($this->getNode('values') as $idx => $value) {
79  if ($idx) {
80  $compiler->raw(', ');
81  }
82 
83  $compiler->subcompile($value);
84  }
85  $compiler->raw(')');
86  } else {
87  if ($this->getAttribute('safe')) {
88  $compiler
89  ->raw("('' === \$tmp = ")
90  ->subcompile($this->getNode('values'))
91  ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())")
92  ;
93  } else {
94  $compiler->subcompile($this->getNode('values'));
95  }
96  }
97  }
98 
99  $compiler->raw(";\n");
100  }
101 }
setNode($name, $node=null)
Sets a node.
Definition: Node.php:202
Compiles a node to PHP code.
Definition: Compiler.php:18
Represents a node in the AST.
Definition: Node.php:18
getAttribute($name)
Gets an attribute.
Definition: Node.php:138
$lineno
Definition: Node.php:22
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
Definition: Compiler.php:207
compile(Twig_Compiler $compiler)
Compiles the node to PHP.
Definition: Set.php:44
setAttribute($name, $value)
Sets an attribute.
Definition: Node.php:153
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:91
Represents a node in the AST.
__construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag=null)
Definition: Set.php:19
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:109
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:121
Represents a text node.
Definition: Text.php:18
count()
Definition: Node.php:217
Represents a set node.
Definition: Set.php:17
getNode($name)
Gets a node by name.
Definition: Node.php:187

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:19 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.