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

Represents a module node. More...

+ Inheritance diagram for Twig_Node_Module:
+ Collaboration diagram for Twig_Node_Module:

Public Member Functions

 __construct (Twig_NodeInterface $body, Twig_Node_Expression $parent=null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $name, $source='')
 
 setIndex ($index)
 
 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

 compileTemplate (Twig_Compiler $compiler)
 
 compileGetParent (Twig_Compiler $compiler)
 
 compileClassHeader (Twig_Compiler $compiler)
 
 compileConstructor (Twig_Compiler $compiler)
 

Private Attributes

 $source
 

Additional Inherited Members

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

Detailed Description

Represents a module node.

Consider this class as being final. If you need to customize the behavior of the generated class, consider adding nodes to the following nodes: display_start, display_end, constructor_start, constructor_end, and class_end.

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

Definition at line 22 of file Module.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_Module::__construct ( Twig_NodeInterface  $body,
Twig_Node_Expression  $parent = null,
Twig_NodeInterface  $blocks,
Twig_NodeInterface  $macros,
Twig_NodeInterface  $traits,
  $embeddedTemplates,
  $name,
  $source = '' 
)

Definition at line 26 of file Module.php.

27 {
28 if (!$name instanceof Twig_Source) {
29 @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
30 $this->source = new Twig_Source($source, $name);
31 } else {
32 $this->source = $name;
33 }
34
35 $nodes = array(
36 'body' => $body,
37 'blocks' => $blocks,
38 'macros' => $macros,
39 'traits' => $traits,
40 'display_start' => new Twig_Node(),
41 'display_end' => new Twig_Node(),
42 'constructor_start' => new Twig_Node(),
43 'constructor_end' => new Twig_Node(),
44 'class_end' => new Twig_Node(),
45 );
46 if (null !== $parent) {
47 $nodes['parent'] = $parent;
48 }
49
50 // embedded templates are set as attributes so that they are only visited once by the visitors
51 parent::__construct($nodes, array(
52 // source to be remove in 2.0
53 'source' => $this->source->getCode(),
54 // filename to be remove in 2.0 (use getTemplateName() instead)
55 'filename' => $this->source->getName(),
56 'index' => null,
57 'embedded_templates' => $embeddedTemplates,
58 ), 1);
59
60 // populate the template name of all node children
61 $this->setTemplateName($this->source->getName());
62 }
Represents a node in the AST.
Definition: Node.php:19
$nodes
Definition: Node.php:20
setTemplateName($name)
Definition: Node.php:219
Holds information about a non-compiled Twig template.
Definition: Source.php:20

References Twig_Node\$name, Twig_Node\$nodes, $source, and Twig_Node\setTemplateName().

+ Here is the call graph for this function:

Member Function Documentation

◆ compile()

Twig_Node_Module::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Reimplemented from Twig_Node.

Definition at line 69 of file Module.php.

70 {
71 $this->compileTemplate($compiler);
72
73 foreach ($this->getAttribute('embedded_templates') as $template) {
74 $compiler->subcompile($template);
75 }
76 }
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:94
compileTemplate(Twig_Compiler $compiler)
Definition: Module.php:78
getAttribute($name)
Definition: Node.php:152
$template

References $template, compileTemplate(), Twig_Node\getAttribute(), and Twig_Compiler\subcompile().

+ Here is the call graph for this function:

◆ compileClassHeader()

Twig_Node_Module::compileClassHeader ( Twig_Compiler  $compiler)
protected

Definition at line 153 of file Module.php.

154 {
155 $compiler
156 ->write("\n\n")
157 // if the template name contains */, add a blank to avoid a PHP parse error
158 ->write('/* '.str_replace('*/', '* /', $this->source->getName())." */\n")
159 ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->source->getName(), $this->getAttribute('index')))
160 ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass()))
161 ->write("{\n")
162 ->indent()
163 ;
164 }
getEnvironment()
Returns the environment instance related to this compiler.
Definition: Compiler.php:50
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:124

References Twig_Compiler\getEnvironment(), and Twig_Compiler\write().

Referenced by compileTemplate().

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

◆ compileConstructor()

Twig_Node_Module::compileConstructor ( Twig_Compiler  $compiler)
protected

Definition at line 166 of file Module.php.

References $i, $key, Twig_Node\$name, Twig_Compiler\addDebugInfo(), compileLoadTemplate(), Twig_Node\count(), Twig_Node\getNode(), Twig_Node\hasNode(), Twig_Compiler\indent(), Twig_Compiler\outdent(), and Twig_Compiler\write().

Referenced by compileTemplate().

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

◆ compileGetParent()

Twig_Node_Module::compileGetParent ( Twig_Compiler  $compiler)
protected

Definition at line 118 of file Module.php.

119 {
120 if (!$this->hasNode('parent')) {
121 return;
122 }
123 $parent = $this->getNode('parent');
124
125 $compiler
126 ->write("protected function doGetParent(array \$context)\n", "{\n")
127 ->indent()
128 ->addDebugInfo($parent)
129 ->write('return ')
130 ;
131
132 if ($parent instanceof Twig_Node_Expression_Constant) {
133 $compiler->subcompile($parent);
134 } else {
135 $compiler
136 ->raw('$this->loadTemplate(')
137 ->subcompile($parent)
138 ->raw(', ')
139 ->repr($this->source->getName())
140 ->raw(', ')
141 ->repr($parent->getTemplateLine())
142 ->raw(')')
143 ;
144 }
145
146 $compiler
147 ->raw(";\n")
148 ->outdent()
149 ->write("}\n\n")
150 ;
151 }
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
hasNode($name)
Definition: Node.php:178
getNode($name)
Definition: Node.php:186

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

Referenced by compileTemplate().

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

◆ compileTemplate()

Twig_Node_Module::compileTemplate ( Twig_Compiler  $compiler)
protected

Definition at line 78 of file Module.php.

79 {
80 if (!$this->getAttribute('index')) {
81 $compiler->write('<?php');
82 }
83
84 $this->compileClassHeader($compiler);
85
86 if (
87 count($this->getNode('blocks'))
88 || count($this->getNode('traits'))
89 || !$this->hasNode('parent')
90 || $this->getNode('parent') instanceof Twig_Node_Expression_Constant
91 || count($this->getNode('constructor_start'))
92 || count($this->getNode('constructor_end'))
93 ) {
94 $this->compileConstructor($compiler);
95 }
96
97 $this->compileGetParent($compiler);
98
99 $this->compileDisplay($compiler);
100
101 $compiler->subcompile($this->getNode('blocks'));
102
103 $this->compileMacros($compiler);
104
105 $this->compileGetTemplateName($compiler);
106
107 $this->compileIsTraitable($compiler);
108
109 $this->compileDebugInfo($compiler);
110
111 $this->compileGetSource($compiler);
112
113 $this->compileGetSourceContext($compiler);
114
115 $this->compileClassFooter($compiler);
116 }
compileGetParent(Twig_Compiler $compiler)
Definition: Module.php:118
compileClassHeader(Twig_Compiler $compiler)
Definition: Module.php:153
compileConstructor(Twig_Compiler $compiler)
Definition: Module.php:166
count()
Definition: Node.php:209
compileGetTemplateName(Twig_Compiler $compiler)
Definition: Module.php:336
compileDisplay(Twig_Compiler $compiler)
Definition: Module.php:295
compileGetSource(Twig_Compiler $compiler)
Definition: Module.php:412
compileClassFooter(Twig_Compiler $compiler)
Definition: Module.php:322
compileIsTraitable(Twig_Compiler $compiler)
Definition: Module.php:349
compileMacros(Twig_Compiler $compiler)
Definition: Module.php:331
compileDebugInfo(Twig_Compiler $compiler)
Definition: Module.php:401
compileGetSourceContext(Twig_Compiler $compiler)
Definition: Module.php:426

References compileClassFooter(), compileClassHeader(), compileConstructor(), compileDebugInfo(), compileDisplay(), compileGetParent(), compileGetSource(), compileGetSourceContext(), compileGetTemplateName(), compileIsTraitable(), compileMacros(), Twig_Node\count(), Twig_Node\getAttribute(), Twig_Node\getNode(), Twig_Node\hasNode(), Twig_Compiler\subcompile(), and Twig_Compiler\write().

Referenced by compile().

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

◆ setIndex()

Twig_Node_Module::setIndex (   $index)

Definition at line 64 of file Module.php.

65 {
66 $this->setAttribute('index', $index);
67 }
setAttribute($name, $value)
Definition: Node.php:165
$index
Definition: metadata.php:60

References $index, and Twig_Node\setAttribute().

+ Here is the call graph for this function:

Field Documentation

◆ $source

Twig_Node_Module::$source
private

Definition at line 24 of file Module.php.

Referenced by __construct().


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