ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Node_With Class Reference

Represents a nested "with" scope. More...

+ Inheritance diagram for Twig_Node_With:
+ Collaboration diagram for Twig_Node_With:

Public Member Functions

 __construct (Twig_Node $body, Twig_Node $variables=null, $only=false, $lineno, $tag=null)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
- Public Member Functions inherited from Twig_Node
 __construct (array $nodes=array(), array $attributes=array(), $lineno=0, $tag=null)
 Constructor. More...
 
 __toString ()
 
 toXml ($asDom=false)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getTemplateLine ()
 
 getLine ()
 
 getNodeTag ()
 
 hasAttribute ($name)
 
 getAttribute ($name)
 
 setAttribute ($name, $value)
 
 removeAttribute ($name)
 
 hasNode ($name)
 
 getNode ($name)
 
 setNode ($name, $node=null)
 
 removeNode ($name)
 
 count ()
 
 getIterator ()
 
 setTemplateName ($name)
 
 getTemplateName ()
 
 setFilename ($name)
 
 getFilename ()
 

Additional Inherited Members

- Protected Attributes inherited from Twig_Node
 $nodes
 
 $attributes
 
 $lineno
 
 $tag
 

Detailed Description

Represents a nested "with" scope.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 17 of file With.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_With::__construct ( Twig_Node  $body,
Twig_Node  $variables = null,
  $only = false,
  $lineno,
  $tag = null 
)

Definition at line 19 of file With.php.

References Twig_Node\$lineno, Twig_Node\$nodes, Twig_Node\$tag, and array.

20  {
21  $nodes = array('body' => $body);
22  if (null !== $variables) {
23  $nodes['variables'] = $variables;
24  }
25 
26  parent::__construct($nodes, array('only' => (bool) $only), $lineno, $tag);
27  }
$lineno
Definition: Node.php:22
$nodes
Definition: Node.php:20
Create styles array
The data for the language used.

Member Function Documentation

◆ compile()

Twig_Node_With::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Implements Twig_NodeInterface.

Definition at line 29 of file With.php.

References Twig_Compiler\addDebugInfo(), Twig_Node\getAttribute(), Twig_Node\getNode(), Twig_Compiler\getVarName(), Twig_Node\hasNode(), Twig_Compiler\subcompile(), and Twig_Compiler\write().

30  {
31  $compiler->addDebugInfo($this);
32 
33  if ($this->hasNode('variables')) {
34  $varsName = $compiler->getVarName();
35  $compiler
36  ->write(sprintf('$%s = ', $varsName))
37  ->subcompile($this->getNode('variables'))
38  ->raw(";\n")
39  ->write(sprintf("if (!is_array(\$%s)) {\n", $varsName))
40  ->indent()
41  ->write("throw new Twig_Error_Runtime('Variables passed to the \"with\" tag must be a hash.');\n")
42  ->outdent()
43  ->write("}\n")
44  ;
45 
46  if ($this->getAttribute('only')) {
47  $compiler->write("\$context = array('_parent' => \$context);\n");
48  } else {
49  $compiler->write("\$context['_parent'] = \$context;\n");
50  }
51 
52  $compiler->write(sprintf("\$context = array_merge(\$context, \$%s);\n", $varsName));
53  } else {
54  $compiler->write("\$context['_parent'] = \$context;\n");
55  }
56 
57  $compiler
58  ->subcompile($this->getNode('body'))
59  ->write("\$context = \$context['_parent'];\n")
60  ;
61  }
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:94
getAttribute($name)
Definition: Node.php:152
hasNode($name)
Definition: Node.php:178
getNode($name)
Definition: Node.php:186
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
Definition: Compiler.php:212
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:124
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: