Import.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Represents an import node.
  12. *
  13. * @author Fabien Potencier <fabien@symfony.com>
  14. */
  15. class Twig_Node_Import extends Twig_Node
  16. {
  17. public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $var, $lineno, $tag = null)
  18. {
  19. parent::__construct(array('expr' => $expr, 'var' => $var), array(), $lineno, $tag);
  20. }
  21. public function compile(Twig_Compiler $compiler)
  22. {
  23. $compiler
  24. ->addDebugInfo($this)
  25. ->write('')
  26. ->subcompile($this->getNode('var'))
  27. ->raw(' = ')
  28. ;
  29. if ($this->getNode('expr') instanceof Twig_Node_Expression_Name && '_self' === $this->getNode('expr')->getAttribute('name')) {
  30. $compiler->raw('$this');
  31. } else {
  32. $compiler
  33. ->raw('$this->loadTemplate(')
  34. ->subcompile($this->getNode('expr'))
  35. ->raw(', ')
  36. ->repr($compiler->getFilename())
  37. ->raw(', ')
  38. ->repr($this->getLine())
  39. ->raw(')')
  40. ;
  41. }
  42. $compiler->raw(";\n");
  43. }
  44. }