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 / NullCoalesceExpression.php

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

47 lines 2.0 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;
12
13 use ElementorDeps\Twig\Compiler;
14 use ElementorDeps\Twig\Node\Expression\Binary\AndBinary;
15 use ElementorDeps\Twig\Node\Expression\Test\DefinedTest;
16 use ElementorDeps\Twig\Node\Expression\Test\NullTest;
17 use ElementorDeps\Twig\Node\Expression\Unary\NotUnary;
18 use ElementorDeps\Twig\Node\Node;
19 class NullCoalesceExpression extends ConditionalExpression
20 {
21 public function __construct(Node $left, Node $right, int $lineno)
22 {
23 $test = new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine());
24 // for "block()", we don't need the null test as the return value is always a string
25 if (!$left instanceof BlockReferenceExpression) {
26 $test = new AndBinary($test, new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()), $left->getTemplateLine());
27 }
28 parent::__construct($test, $left, $right, $lineno);
29 }
30 public function compile(Compiler $compiler) : void
31 {
32 /*
33 * This optimizes only one case. PHP 7 also supports more complex expressions
34 * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works,
35 * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced
36 * cases might be implemented as an optimizer node visitor, but has not been done
37 * as benefits are probably not worth the added complexity.
38 */
39 if ($this->getNode('expr2') instanceof NameExpression) {
40 $this->getNode('expr2')->setAttribute('always_defined', \true);
41 $compiler->raw('((')->subcompile($this->getNode('expr2'))->raw(') ?? (')->subcompile($this->getNode('expr3'))->raw('))');
42 } else {
43 parent::compile($compiler);
44 }
45 }
46 }
47