1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-23 04:44:53 +01:00
vichan/inc/lib/Twig/Node/Expression/GetAttr.php

75 lines
2.6 KiB
PHP
Raw Normal View History

2011-10-05 06:22:53 +02:00
<?php
/*
* This file is part of Twig.
*
2018-05-10 12:24:53 +02:00
* (c) Fabien Potencier
* (c) Armin Ronacher
2011-10-05 06:22:53 +02:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
{
2018-05-10 12:24:53 +02:00
public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression $arguments = null, $type, $lineno)
2011-10-05 06:22:53 +02:00
{
2018-05-10 12:24:53 +02:00
$nodes = array('node' => $node, 'attribute' => $attribute);
if (null !== $arguments) {
$nodes['arguments'] = $arguments;
}
parent::__construct($nodes, array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false), $lineno);
2011-10-05 06:22:53 +02:00
}
public function compile(Twig_Compiler $compiler)
{
2018-05-10 12:24:53 +02:00
if ($this->getAttribute('disable_c_ext')) {
@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);
}
2013-08-01 21:20:12 +02:00
if (function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) {
$compiler->raw('twig_template_get_attributes($this, ');
2011-10-05 06:22:53 +02:00
} else {
2013-08-01 21:20:12 +02:00
$compiler->raw('$this->getAttribute(');
2011-10-05 06:22:53 +02:00
}
2013-08-01 21:20:12 +02:00
if ($this->getAttribute('ignore_strict_check')) {
$this->getNode('node')->setAttribute('ignore_strict_check', true);
2011-10-05 06:22:53 +02:00
}
2013-08-01 21:20:12 +02:00
$compiler->subcompile($this->getNode('node'));
$compiler->raw(', ')->subcompile($this->getNode('attribute'));
2018-05-10 12:24:53 +02:00
// only generate optional arguments when needed (to make generated code more readable)
$needFourth = $this->getAttribute('ignore_strict_check');
$needThird = $needFourth || $this->getAttribute('is_defined_test');
$needSecond = $needThird || Twig_Template::ANY_CALL !== $this->getAttribute('type');
$needFirst = $needSecond || $this->hasNode('arguments');
2013-08-01 21:20:12 +02:00
2018-05-10 12:24:53 +02:00
if ($needFirst) {
if ($this->hasNode('arguments')) {
$compiler->raw(', ')->subcompile($this->getNode('arguments'));
} else {
$compiler->raw(', array()');
2013-08-01 21:20:12 +02:00
}
2018-05-10 12:24:53 +02:00
}
2013-08-01 21:20:12 +02:00
2018-05-10 12:24:53 +02:00
if ($needSecond) {
$compiler->raw(', ')->repr($this->getAttribute('type'));
}
2013-08-01 21:20:12 +02:00
2018-05-10 12:24:53 +02:00
if ($needThird) {
$compiler->raw(', ')->repr($this->getAttribute('is_defined_test'));
}
if ($needFourth) {
$compiler->raw(', ')->repr($this->getAttribute('ignore_strict_check'));
2013-08-01 21:20:12 +02:00
}
$compiler->raw(')');
2011-10-05 06:22:53 +02:00
}
}
2018-05-10 12:24:53 +02:00
class_alias('Twig_Node_Expression_GetAttr', 'Twig\Node\Expression\GetAttrExpression', false);