PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.3
Elementor Website Builder – more than just a page builder v3.28.3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / vendor_prefixed / twig / src / Node / Expression / Test / DefinedTest.php

DefinedTest.php in Elementor Website Builder – more than just a page builder 3.28.3, at vendor_prefixed/twig/src/Node/Expression/Test/DefinedTest.php

69 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace ElementorDeps\Twig\Node\Expression\Test;
12
13 use ElementorDeps\Twig\Compiler;
14 use ElementorDeps\Twig\Error\SyntaxError;
15 use ElementorDeps\Twig\Node\Expression\ArrayExpression;
16 use ElementorDeps\Twig\Node\Expression\BlockReferenceExpression;
17 use ElementorDeps\Twig\Node\Expression\ConstantExpression;
18 use ElementorDeps\Twig\Node\Expression\FunctionExpression;
19 use ElementorDeps\Twig\Node\Expression\GetAttrExpression;
20 use ElementorDeps\Twig\Node\Expression\MethodCallExpression;
21 use ElementorDeps\Twig\Node\Expression\NameExpression;
22 use ElementorDeps\Twig\Node\Expression\TestExpression;
23 use ElementorDeps\Twig\Node\Node;
24 /**
25 * Checks if a variable is defined in the current context.
26 *
27 * {# defined works with variable names and variable attributes #}
28 * {% if foo is defined %}
29 * {# ... #}
30 * {% endif %}
31 *
32 * @author Fabien Potencier <fabien@symfony.com>
33 */
34 class DefinedTest extends TestExpression
35 {
36 public function __construct(Node $node, string $name, ?Node $arguments, int $lineno)
37 {
38 if ($node instanceof NameExpression) {
39 $node->setAttribute('is_defined_test', \true);
40 } elseif ($node instanceof GetAttrExpression) {
41 $node->setAttribute('is_defined_test', \true);
42 $this->changeIgnoreStrictCheck($node);
43 } elseif ($node instanceof BlockReferenceExpression) {
44 $node->setAttribute('is_defined_test', \true);
45 } elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) {
46 $node->setAttribute('is_defined_test', \true);
47 } elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) {
48 $node = new ConstantExpression(\true, $node->getTemplateLine());
49 } elseif ($node instanceof MethodCallExpression) {
50 $node->setAttribute('is_defined_test', \true);
51 } else {
52 throw new SyntaxError('The "defined" test only works with simple variables.', $lineno);
53 }
54 parent::__construct($node, $name, $arguments, $lineno);
55 }
56 private function changeIgnoreStrictCheck(GetAttrExpression $node)
57 {
58 $node->setAttribute('optimizable', \false);
59 $node->setAttribute('ignore_strict_check', \true);
60 if ($node->getNode('node') instanceof GetAttrExpression) {
61 $this->changeIgnoreStrictCheck($node->getNode('node'));
62 }
63 }
64 public function compile(Compiler $compiler) : void
65 {
66 $compiler->subcompile($this->getNode('node'));
67 }
68 }
69