75814265c9a5219545ac54c1c672719cc503cf78
[yaffs-website] / vendor / twig / twig / lib / Twig / Node / Expression / GetAttr.php
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 class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
13 {
14     public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression $arguments = null, $type, $lineno)
15     {
16         $nodes = array('node' => $node, 'attribute' => $attribute);
17         if (null !== $arguments) {
18             $nodes['arguments'] = $arguments;
19         }
20
21         parent::__construct($nodes, array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false), $lineno);
22     }
23
24     public function compile(Twig_Compiler $compiler)
25     {
26         if ($this->getAttribute('disable_c_ext')) {
27             @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED);
28         }
29
30         if (function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) {
31             $compiler->raw('twig_template_get_attributes($this, ');
32         } else {
33             $compiler->raw('$this->getAttribute(');
34         }
35
36         if ($this->getAttribute('ignore_strict_check')) {
37             $this->getNode('node')->setAttribute('ignore_strict_check', true);
38         }
39
40         $compiler->subcompile($this->getNode('node'));
41
42         $compiler->raw(', ')->subcompile($this->getNode('attribute'));
43
44         // only generate optional arguments when needed (to make generated code more readable)
45         $needFourth = $this->getAttribute('ignore_strict_check');
46         $needThird = $needFourth || $this->getAttribute('is_defined_test');
47         $needSecond = $needThird || Twig_Template::ANY_CALL !== $this->getAttribute('type');
48         $needFirst = $needSecond || $this->hasNode('arguments');
49
50         if ($needFirst) {
51             if ($this->hasNode('arguments')) {
52                 $compiler->raw(', ')->subcompile($this->getNode('arguments'));
53             } else {
54                 $compiler->raw(', array()');
55             }
56         }
57
58         if ($needSecond) {
59             $compiler->raw(', ')->repr($this->getAttribute('type'));
60         }
61
62         if ($needThird) {
63             $compiler->raw(', ')->repr($this->getAttribute('is_defined_test'));
64         }
65
66         if ($needFourth) {
67             $compiler->raw(', ')->repr($this->getAttribute('ignore_strict_check'));
68         }
69
70         $compiler->raw(')');
71     }
72 }