diff options
author | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
commit | 2eed7b082f83630301e51f57ca8394de228a8605 (patch) | |
tree | 1d19962d22d30f99317d9276e4bae7744fc93fc2 /public/system/library/template/Twig/Node/Expression/Test | |
download | librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.lz librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.xz librecart-2eed7b082f83630301e51f57ca8394de228a8605.zip |
first commit
Diffstat (limited to 'public/system/library/template/Twig/Node/Expression/Test')
7 files changed, 259 insertions, 0 deletions
diff --git a/public/system/library/template/Twig/Node/Expression/Test/Constant.php b/public/system/library/template/Twig/Node/Expression/Test/Constant.php new file mode 100644 index 0000000..de55f5f --- /dev/null +++ b/public/system/library/template/Twig/Node/Expression/Test/Constant.php @@ -0,0 +1,46 @@ +<?php + +/* + * This file is part of Twig. + * + * (c) 2011 Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Checks if a variable is the exact same value as a constant. + * + * <pre> + * {% if post.status is constant('Post::PUBLISHED') %} + * the status attribute is exactly the same as Post::PUBLISHED + * {% endif %} + * </pre> + * + * @author Fabien Potencier <fabien@symfony.com> + */ +class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test +{ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' === constant(') + ; + + if ($this->getNode('arguments')->hasNode(1)) { + $compiler + ->raw('get_class(') + ->subcompile($this->getNode('arguments')->getNode(1)) + ->raw(')."::".') + ; + } + + $compiler + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw('))') + ; + } +} diff --git a/public/system/library/template/Twig/Node/Expression/Test/Defined.php b/public/system/library/template/Twig/Node/Expression/Test/Defined.php new file mode 100644 index 0000000..3dc6ff5 --- /dev/null +++ b/public/system/library/template/Twig/Node/Expression/Test/Defined.php @@ -0,0 +1,56 @@ +<?php + +/* + * This file is part of Twig. + * + * (c) 2011 Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Checks if a variable is defined in the current context. + * + * <pre> + * {# defined works with variable names and variable attributes #} + * {% if foo is defined %} + * {# ... #} + * {% endif %} + * </pre> + * + * @author Fabien Potencier <fabien@symfony.com> + */ +class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test +{ + public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) + { + if ($node instanceof Twig_Node_Expression_Name) { + $node->setAttribute('is_defined_test', true); + } elseif ($node instanceof Twig_Node_Expression_GetAttr) { + $node->setAttribute('is_defined_test', true); + + $this->changeIgnoreStrictCheck($node); + } elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) { + $node = new Twig_Node_Expression_Constant(true, $node->getLine()); + } else { + throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getLine()); + } + + parent::__construct($node, $name, $arguments, $lineno); + } + + protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node) + { + $node->setAttribute('ignore_strict_check', true); + + if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) { + $this->changeIgnoreStrictCheck($node->getNode('node')); + } + } + + public function compile(Twig_Compiler $compiler) + { + $compiler->subcompile($this->getNode('node')); + } +} diff --git a/public/system/library/template/Twig/Node/Expression/Test/Divisibleby.php b/public/system/library/template/Twig/Node/Expression/Test/Divisibleby.php new file mode 100644 index 0000000..d5bed23 --- /dev/null +++ b/public/system/library/template/Twig/Node/Expression/Test/Divisibleby.php @@ -0,0 +1,33 @@ +<?php + +/* + * This file is part of Twig. + * + * (c) 2011 Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Checks if a variable is divisible by a number. + * + * <pre> + * {% if loop.index is divisible by(3) %} + * </pre> + * + * @author Fabien Potencier <fabien@symfony.com> + */ +class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test +{ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->raw('(0 == ') + ->subcompile($this->getNode('node')) + ->raw(' % ') + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw(')') + ; + } +} diff --git a/public/system/library/template/Twig/Node/Expression/Test/Even.php b/public/system/library/template/Twig/Node/Expression/Test/Even.php new file mode 100644 index 0000000..d7853e8 --- /dev/null +++ b/public/system/library/template/Twig/Node/Expression/Test/Even.php @@ -0,0 +1,32 @@ +<?php + +/* + * This file is part of Twig. + * + * (c) 2011 Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Checks if a number is even. + * + * <pre> + * {{ var is even }} + * </pre> + * + * @author Fabien Potencier <fabien@symfony.com> + */ +class Twig_Node_Expression_Test_Even extends Twig_Node_Expression_Test +{ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' % 2 == 0') + ->raw(')') + ; + } +} diff --git a/public/system/library/template/Twig/Node/Expression/Test/Null.php b/public/system/library/template/Twig/Node/Expression/Test/Null.php new file mode 100644 index 0000000..1c83825 --- /dev/null +++ b/public/system/library/template/Twig/Node/Expression/Test/Null.php @@ -0,0 +1,31 @@ +<?php + +/* + * This file is part of Twig. + * + * (c) 2011 Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Checks that a variable is null. + * + * <pre> + * {{ var is none }} + * </pre> + * + * @author Fabien Potencier <fabien@symfony.com> + */ +class Twig_Node_Expression_Test_Null extends Twig_Node_Expression_Test +{ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->raw('(null === ') + ->subcompile($this->getNode('node')) + ->raw(')') + ; + } +} diff --git a/public/system/library/template/Twig/Node/Expression/Test/Odd.php b/public/system/library/template/Twig/Node/Expression/Test/Odd.php new file mode 100644 index 0000000..421c19e --- /dev/null +++ b/public/system/library/template/Twig/Node/Expression/Test/Odd.php @@ -0,0 +1,32 @@ +<?php + +/* + * This file is part of Twig. + * + * (c) 2011 Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Checks if a number is odd. + * + * <pre> + * {{ var is odd }} + * </pre> + * + * @author Fabien Potencier <fabien@symfony.com> + */ +class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test +{ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' % 2 == 1') + ->raw(')') + ; + } +} diff --git a/public/system/library/template/Twig/Node/Expression/Test/Sameas.php b/public/system/library/template/Twig/Node/Expression/Test/Sameas.php new file mode 100644 index 0000000..b48905e --- /dev/null +++ b/public/system/library/template/Twig/Node/Expression/Test/Sameas.php @@ -0,0 +1,29 @@ +<?php + +/* + * This file is part of Twig. + * + * (c) 2011 Fabien Potencier + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Checks if a variable is the same as another one (=== in PHP). + * + * @author Fabien Potencier <fabien@symfony.com> + */ +class Twig_Node_Expression_Test_Sameas extends Twig_Node_Expression_Test +{ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->raw('(') + ->subcompile($this->getNode('node')) + ->raw(' === ') + ->subcompile($this->getNode('arguments')->getNode(0)) + ->raw(')') + ; + } +} |