Conditional.php 902B

1234567891011121314151617181920212223242526272829303132
  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_Conditional extends Twig_Node_Expression
  12. {
  13. public function __construct(Twig_Node_Expression $expr1, Twig_Node_Expression $expr2, Twig_Node_Expression $expr3, $lineno)
  14. {
  15. parent::__construct(array('expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3), array(), $lineno);
  16. }
  17. public function compile(Twig_Compiler $compiler)
  18. {
  19. $compiler
  20. ->raw('((')
  21. ->subcompile($this->getNode('expr1'))
  22. ->raw(') ? (')
  23. ->subcompile($this->getNode('expr2'))
  24. ->raw(') : (')
  25. ->subcompile($this->getNode('expr3'))
  26. ->raw('))')
  27. ;
  28. }
  29. }