Divisibleby.php 765B

1234567891011121314151617181920212223242526272829303132333435
  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. /**
  11. * Checks if a variable is divisible by a number.
  12. *
  13. * <pre>
  14. * {% if loop.index is divisibleby(3) %}
  15. * </pre>
  16. *
  17. * @package twig
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test
  21. {
  22. public function compile(Twig_Compiler $compiler)
  23. {
  24. $compiler
  25. ->raw('(0 == ')
  26. ->subcompile($this->getNode('node'))
  27. ->raw(' % ')
  28. ->subcompile($this->getNode('arguments')->getNode(0))
  29. ->raw(')')
  30. ;
  31. }
  32. }