1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-15 09:01:21 +01:00
vichan/inc/lib/Twig/Node/Expression/GetAttr.php

64 lines
2.3 KiB
PHP
Raw Normal View History

2011-10-05 06:22:53 +02:00
<?php
/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
* (c) 2009 Armin Ronacher
*
* 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
{
2015-03-11 00:16:45 +01: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
{
2013-08-01 21:20:12 +02:00
parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), 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)
{
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'));
2015-03-11 00:16:45 +01: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 || null !== $this->getNode('arguments');
if ($needFirst) {
if (null !== $this->getNode('arguments')) {
$compiler->raw(', ')->subcompile($this->getNode('arguments'));
} else {
$compiler->raw(', array()');
2013-08-01 21:20:12 +02:00
}
2015-03-11 00:16:45 +01:00
}
2013-08-01 21:20:12 +02:00
2015-03-11 00:16:45 +01:00
if ($needSecond) {
$compiler->raw(', ')->repr($this->getAttribute('type'));
}
2013-08-01 21:20:12 +02:00
2015-03-11 00:16:45 +01: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
}
}