ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
BlockReference.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  * (c) Armin Ronacher
8  *
9  * For the full copyright and license information, please view the LICENSE
10  * file that was distributed with this source code.
11  */
12 
19 {
23  public function __construct(Twig_NodeInterface $name, $template = null, $lineno, $tag = null)
24  {
25  if (is_bool($template)) {
26  @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
27 
28  $template = null;
29  }
30 
31  $nodes = array('name' => $name);
32  if (null !== $template) {
33  $nodes['template'] = $template;
34  }
35 
36  parent::__construct($nodes, array('is_defined_test' => false, 'output' => false), $lineno, $tag);
37  }
38 
39  public function compile(Twig_Compiler $compiler)
40  {
41  if ($this->getAttribute('is_defined_test')) {
42  $this->compileTemplateCall($compiler, 'hasBlock');
43  } else {
44  if ($this->getAttribute('output')) {
45  $compiler->addDebugInfo($this);
46 
47  $this
48  ->compileTemplateCall($compiler, 'displayBlock')
49  ->raw(";\n");
50  } else {
51  $this->compileTemplateCall($compiler, 'renderBlock');
52  }
53  }
54  }
55 
56  private function compileTemplateCall(Twig_Compiler $compiler, $method)
57  {
58  if (!$this->hasNode('template')) {
59  $compiler->write('$this');
60  } else {
61  $compiler
62  ->write('$this->loadTemplate(')
63  ->subcompile($this->getNode('template'))
64  ->raw(', ')
65  ->repr($this->getTemplateName())
66  ->raw(', ')
67  ->repr($this->getTemplateLine())
68  ->raw(')')
69  ;
70  }
71 
72  $compiler->raw(sprintf('->%s', $method));
73  $this->compileBlockArguments($compiler);
74 
75  return $compiler;
76  }
77 
78  private function compileBlockArguments(Twig_Compiler $compiler)
79  {
80  $compiler
81  ->raw('(')
82  ->subcompile($this->getNode('name'))
83  ->raw(', $context');
84 
85  if (!$this->hasNode('template')) {
86  $compiler->raw(', $blocks');
87  }
88 
89  return $compiler->raw(')');
90  }
91 }
92 
93 class_alias('Twig_Node_Expression_BlockReference', 'Twig\Node\Expression\BlockReferenceExpression', false);
$lineno
Definition: Node.php:22
compileBlockArguments(Twig_Compiler $compiler)
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
Represents a node in the AST.
getTemplateName()
Definition: Node.php:229
$template
__construct(Twig_NodeInterface $name, $template=null, $lineno, $tag=null)
Abstract class for all nodes that represents an expression.
Definition: Expression.php:18
$nodes
Definition: Node.php:20
compile(Twig_Compiler $compiler)
Compiles the node to PHP.
getAttribute($name)
Definition: Node.php:152
getTemplateLine()
Definition: Node.php:121
hasNode($name)
Definition: Node.php:178
Create styles array
The data for the language used.
compileTemplateCall(Twig_Compiler $compiler, $method)
getNode($name)
Definition: Node.php:186
Represents a block call node.
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