BlockReference.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /**
  12. * Represents a block call node.
  13. *
  14. * @package twig
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
  18. {
  19. public function __construct(Twig_NodeInterface $name, $asString = false, $lineno, $tag = null)
  20. {
  21. parent::__construct(array('name' => $name), array('as_string' => $asString, 'output' => false), $lineno, $tag);
  22. }
  23. /**
  24. * Compiles the node to PHP.
  25. *
  26. * @param Twig_Compiler A Twig_Compiler instance
  27. */
  28. public function compile(Twig_Compiler $compiler)
  29. {
  30. if ($this->getAttribute('as_string')) {
  31. $compiler->raw('(string) ');
  32. }
  33. if ($this->getAttribute('output')) {
  34. $compiler
  35. ->addDebugInfo($this)
  36. ->write("\$this->displayBlock(")
  37. ->subcompile($this->getNode('name'))
  38. ->raw(", \$context, \$blocks);\n")
  39. ;
  40. } else {
  41. $compiler
  42. ->raw("\$this->renderBlock(")
  43. ->subcompile($this->getNode('name'))
  44. ->raw(", \$context, \$blocks)")
  45. ;
  46. }
  47. }
  48. }