SetTemp.php 840B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2011 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. class Twig_Node_SetTemp extends Twig_Node
  11. {
  12. public function __construct($name, $lineno)
  13. {
  14. parent::__construct(array(), array('name' => $name), $lineno);
  15. }
  16. public function compile(Twig_Compiler $compiler)
  17. {
  18. $name = $this->getAttribute('name');
  19. $compiler
  20. ->addDebugInfo($this)
  21. ->write('if (isset($context[')
  22. ->string($name)
  23. ->raw('])) { $_')
  24. ->raw($name)
  25. ->raw('_ = $context[')
  26. ->repr($name)
  27. ->raw(']; } else { $_')
  28. ->raw($name)
  29. ->raw("_ = null; }\n")
  30. ;
  31. }
  32. }