ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Node_Include Class Reference

Represents an include node. More...

+ Inheritance diagram for Twig_Node_Include:
+ Collaboration diagram for Twig_Node_Include:

Public Member Functions

 __construct (Twig_Node_Expression $expr, Twig_Node_Expression $variables=null, $only=false, $ignoreMissing=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 ()
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getLine ()
 
 getNodeTag ()
 

Protected Member Functions

 addGetTemplate (Twig_Compiler $compiler)
 
 addTemplateArguments (Twig_Compiler $compiler)
 

Additional Inherited Members

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

Detailed Description

Represents an include node.

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

Definition at line 18 of file Include.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_Include::__construct ( Twig_Node_Expression  $expr,
Twig_Node_Expression  $variables = null,
  $only = false,
  $ignoreMissing = false,
  $lineno,
  $tag = null 
)

Definition at line 20 of file Include.php.

21 {
22 $nodes = array('expr' => $expr);
23 if (null !== $variables) {
24 $nodes['variables'] = $variables;
25 }
26
27 parent::__construct($nodes, array('only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing), $lineno, $tag);
28 }
$lineno
Definition: Node.php:22
$nodes
Definition: Node.php:20

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

Member Function Documentation

◆ addGetTemplate()

Twig_Node_Include::addGetTemplate ( Twig_Compiler  $compiler)
protected

Reimplemented in Twig_Node_Embed.

Definition at line 61 of file Include.php.

62 {
63 $compiler
64 ->write('$this->loadTemplate(')
65 ->subcompile($this->getNode('expr'))
66 ->raw(', ')
67 ->repr($this->getTemplateName())
68 ->raw(', ')
69 ->repr($this->getTemplateLine())
70 ->raw(')')
71 ;
72 }
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:124
getTemplateName()
Definition: Node.php:229
getTemplateLine()
Definition: Node.php:121
getNode($name)
Definition: Node.php:186

References Twig_Node\getNode(), Twig_Node\getTemplateLine(), Twig_Node\getTemplateName(), and Twig_Compiler\write().

Referenced by compile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addTemplateArguments()

Twig_Node_Include::addTemplateArguments ( Twig_Compiler  $compiler)
protected

Definition at line 74 of file Include.php.

75 {
76 if (!$this->hasNode('variables')) {
77 $compiler->raw(false === $this->getAttribute('only') ? '$context' : 'array()');
78 } elseif (false === $this->getAttribute('only')) {
79 $compiler
80 ->raw('array_merge($context, ')
81 ->subcompile($this->getNode('variables'))
82 ->raw(')')
83 ;
84 } else {
85 $compiler->subcompile($this->getNode('variables'));
86 }
87 }
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:94
hasNode($name)
Definition: Node.php:178
getAttribute($name)
Definition: Node.php:152

References Twig_Node\getAttribute(), Twig_Node\getNode(), Twig_Node\hasNode(), Twig_Compiler\raw(), and Twig_Compiler\subcompile().

Referenced by compile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compile()

Twig_Node_Include::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Reimplemented from Twig_Node.

Definition at line 30 of file Include.php.

31 {
32 $compiler->addDebugInfo($this);
33
34 if ($this->getAttribute('ignore_missing')) {
35 $compiler
36 ->write("try {\n")
37 ->indent()
38 ;
39 }
40
41 $this->addGetTemplate($compiler);
42
43 $compiler->raw('->display(');
44
45 $this->addTemplateArguments($compiler);
46
47 $compiler->raw(");\n");
48
49 if ($this->getAttribute('ignore_missing')) {
50 $compiler
51 ->outdent()
52 ->write("} catch (Twig_Error_Loader \$e) {\n")
53 ->indent()
54 ->write("// ignore missing template\n")
55 ->outdent()
56 ->write("}\n\n")
57 ;
58 }
59 }
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
Definition: Compiler.php:212
outdent($step=1)
Outdents the generated code.
Definition: Compiler.php:267
addGetTemplate(Twig_Compiler $compiler)
Definition: Include.php:61
addTemplateArguments(Twig_Compiler $compiler)
Definition: Include.php:74

References Twig_Compiler\addDebugInfo(), addGetTemplate(), addTemplateArguments(), Twig_Node\getAttribute(), Twig_Compiler\outdent(), Twig_Compiler\raw(), and Twig_Compiler\write().

+ Here is the call graph for this function:

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