ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
93class_alias('Twig_Node_Expression_BlockReference', 'Twig\Node\Expression\BlockReferenceExpression', false);
An exception for terminatinating execution or to throw for unit testing.
Compiles a node to PHP code.
Definition: Compiler.php:19
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
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
Represents a block call node.
compileBlockArguments(Twig_Compiler $compiler)
compile(Twig_Compiler $compiler)
Compiles the node to PHP.
__construct(Twig_NodeInterface $name, $template=null, $lineno, $tag=null)
compileTemplateCall(Twig_Compiler $compiler, $method)
Abstract class for all nodes that represents an expression.
Definition: Expression.php:19
hasNode($name)
Definition: Node.php:178
getAttribute($name)
Definition: Node.php:152
getTemplateName()
Definition: Node.php:229
$lineno
Definition: Node.php:22
getTemplateLine()
Definition: Node.php:121
getNode($name)
Definition: Node.php:186
$nodes
Definition: Node.php:20
$template
Represents a node in the AST.