GetAttr.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_NodeInterface $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(', array(');
  31. foreach ($this->getNode('arguments') as $node) {
  32. $compiler
  33. ->subcompile($node)
  34. ->raw(', ')
  35. ;
  36. }
  37. $compiler->raw(')');
  38. if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
  39. $compiler->raw(', ')->repr($this->getAttribute('type'));
  40. }
  41. if ($this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
  42. $compiler->raw(', '.($this->getAttribute('is_defined_test') ? 'true' : 'false'));
  43. }
  44. if ($this->getAttribute('ignore_strict_check')) {
  45. $compiler->raw(', '.($this->getAttribute('ignore_strict_check') ? 'true' : 'false'));
  46. }
  47. }
  48. $compiler->raw(')');
  49. }
  50. }