GetAttr.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 Fabien Potencier
  6. * (c) 2009 Armin Ronacher
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
  12. {
  13. public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression_Array $arguments, $type, $lineno)
  14. {
  15. parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false), $lineno);
  16. }
  17. public function compile(Twig_Compiler $compiler)
  18. {
  19. if (function_exists('twig_template_get_attributes')) {
  20. $compiler->raw('twig_template_get_attributes($this, ');
  21. } else {
  22. $compiler->raw('$this->getAttribute(');
  23. }
  24. if ($this->getAttribute('ignore_strict_check')) {
  25. $this->getNode('node')->setAttribute('ignore_strict_check', true);
  26. }
  27. $compiler->subcompile($this->getNode('node'));
  28. $compiler->raw(', ')->subcompile($this->getNode('attribute'));
  29. if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
  30. $compiler->raw(', ')->subcompile($this->getNode('arguments'));
  31. if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
  32. $compiler->raw(', ')->repr($this->getAttribute('type'));
  33. }
  34. if ($this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
  35. $compiler->raw(', '.($this->getAttribute('is_defined_test') ? 'true' : 'false'));
  36. }
  37. if ($this->getAttribute('ignore_strict_check')) {
  38. $compiler->raw(', '.($this->getAttribute('ignore_strict_check') ? 'true' : 'false'));
  39. }
  40. }
  41. $compiler->raw(')');
  42. }
  43. }