dvadf
File manager - Edit - /home/centroca/public_html/Expression.tar
Back
AbstractExpression.php 0000644 00000001156 15253176377 0011123 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Node\Node; /** * Abstract class for all nodes that represents an expression. * * @author Fabien Potencier <fabien@symfony.com> */ abstract class AbstractExpression extends Node { public function isGenerator() : bool { return $this->hasAttribute('is_generator') && $this->getAttribute('is_generator'); } } NullCoalesceExpression.php 0000644 00000003766 15253176377 0011742 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\Binary\AndBinary; use ElementorDeps\Twig\Node\Expression\Test\DefinedTest; use ElementorDeps\Twig\Node\Expression\Test\NullTest; use ElementorDeps\Twig\Node\Expression\Unary\NotUnary; use ElementorDeps\Twig\Node\Node; class NullCoalesceExpression extends ConditionalExpression { public function __construct(Node $left, Node $right, int $lineno) { $test = new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine()); // for "block()", we don't need the null test as the return value is always a string if (!$left instanceof BlockReferenceExpression) { $test = new AndBinary($test, new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()), $left->getTemplateLine()); } parent::__construct($test, $left, $right, $lineno); } public function compile(Compiler $compiler) : void { /* * This optimizes only one case. PHP 7 also supports more complex expressions * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works, * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced * cases might be implemented as an optimizer node visitor, but has not been done * as benefits are probably not worth the added complexity. */ if ($this->getNode('expr2') instanceof NameExpression) { $this->getNode('expr2')->setAttribute('always_defined', \true); $compiler->raw('((')->subcompile($this->getNode('expr2'))->raw(') ?? (')->subcompile($this->getNode('expr3'))->raw('))'); } else { parent::compile($compiler); } } } Test/DivisiblebyTest.php 0000644 00000001370 15253176377 0011322 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Test; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\TestExpression; /** * Checks if a variable is divisible by a number. * * {% if loop.index is divisible by(3) %} * * @author Fabien Potencier <fabien@symfony.com> */ class DivisiblebyTest extends TestExpression { public function compile(Compiler $compiler) : void { $compiler->raw('(0 == ')->subcompile($this->getNode('node'))->raw(' % ')->subcompile($this->getNode('arguments')->getNode('0'))->raw(')'); } } Test/ConstantTest.php 0000644 00000002065 15253176377 0010650 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Test; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\TestExpression; /** * Checks if a variable is the exact same value as a constant. * * {% if post.status is constant('Post::PUBLISHED') %} * the status attribute is exactly the same as Post::PUBLISHED * {% endif %} * * @author Fabien Potencier <fabien@symfony.com> */ class ConstantTest extends TestExpression { public function compile(Compiler $compiler) : void { $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('))'); } } Test/NullTest.php 0000644 00000001216 15253176377 0007766 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Test; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\TestExpression; /** * Checks that a variable is null. * * {{ var is none }} * * @author Fabien Potencier <fabien@symfony.com> */ class NullTest extends TestExpression { public function compile(Compiler $compiler) : void { $compiler->raw('(null === ')->subcompile($this->getNode('node'))->raw(')'); } } Test/DefinedTest.php 0000644 00000005253 15253176377 0010417 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Test; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Error\SyntaxError; use ElementorDeps\Twig\Node\Expression\ArrayExpression; use ElementorDeps\Twig\Node\Expression\BlockReferenceExpression; use ElementorDeps\Twig\Node\Expression\ConstantExpression; use ElementorDeps\Twig\Node\Expression\FunctionExpression; use ElementorDeps\Twig\Node\Expression\GetAttrExpression; use ElementorDeps\Twig\Node\Expression\MethodCallExpression; use ElementorDeps\Twig\Node\Expression\NameExpression; use ElementorDeps\Twig\Node\Expression\TestExpression; use ElementorDeps\Twig\Node\Node; /** * Checks if a variable is defined in the current context. * * {# defined works with variable names and variable attributes #} * {% if foo is defined %} * {# ... #} * {% endif %} * * @author Fabien Potencier <fabien@symfony.com> */ class DefinedTest extends TestExpression { public function __construct(Node $node, string $name, ?Node $arguments, int $lineno) { if ($node instanceof NameExpression) { $node->setAttribute('is_defined_test', \true); } elseif ($node instanceof GetAttrExpression) { $node->setAttribute('is_defined_test', \true); $this->changeIgnoreStrictCheck($node); } elseif ($node instanceof BlockReferenceExpression) { $node->setAttribute('is_defined_test', \true); } elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) { $node->setAttribute('is_defined_test', \true); } elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) { $node = new ConstantExpression(\true, $node->getTemplateLine()); } elseif ($node instanceof MethodCallExpression) { $node->setAttribute('is_defined_test', \true); } else { throw new SyntaxError('The "defined" test only works with simple variables.', $lineno); } parent::__construct($node, $name, $arguments, $lineno); } private function changeIgnoreStrictCheck(GetAttrExpression $node) { $node->setAttribute('optimizable', \false); $node->setAttribute('ignore_strict_check', \true); if ($node->getNode('node') instanceof GetAttrExpression) { $this->changeIgnoreStrictCheck($node->getNode('node')); } } public function compile(Compiler $compiler) : void { $compiler->subcompile($this->getNode('node')); } } Test/SameasTest.php 0000644 00000001321 15253176377 0010262 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Test; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\TestExpression; /** * Checks if a variable is the same as another one (=== in PHP). * * @author Fabien Potencier <fabien@symfony.com> */ class SameasTest extends TestExpression { public function compile(Compiler $compiler) : void { $compiler->raw('(')->subcompile($this->getNode('node'))->raw(' === ')->subcompile($this->getNode('arguments')->getNode('0'))->raw(')'); } } Test/OddTest.php 0000644 00000001220 15253176377 0007555 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Test; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\TestExpression; /** * Checks if a number is odd. * * {{ var is odd }} * * @author Fabien Potencier <fabien@symfony.com> */ class OddTest extends TestExpression { public function compile(Compiler $compiler) : void { $compiler->raw('(')->subcompile($this->getNode('node'))->raw(' % 2 != 0')->raw(')'); } } Test/EvenTest.php 0000644 00000001223 15253176377 0007747 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Test; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\TestExpression; /** * Checks if a number is even. * * {{ var is even }} * * @author Fabien Potencier <fabien@symfony.com> */ class EvenTest extends TestExpression { public function compile(Compiler $compiler) : void { $compiler->raw('(')->subcompile($this->getNode('node'))->raw(' % 2 == 0')->raw(')'); } } GetAttrExpression.php 0000644 00000005656 15253176377 0010743 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Extension\SandboxExtension; use ElementorDeps\Twig\Template; class GetAttrExpression extends AbstractExpression { public function __construct(AbstractExpression $node, AbstractExpression $attribute, ?AbstractExpression $arguments, string $type, int $lineno) { $nodes = ['node' => $node, 'attribute' => $attribute]; if (null !== $arguments) { $nodes['arguments'] = $arguments; } parent::__construct($nodes, ['type' => $type, 'is_defined_test' => \false, 'ignore_strict_check' => \false, 'optimizable' => \true], $lineno); } public function compile(Compiler $compiler) : void { $env = $compiler->getEnvironment(); $arrayAccessSandbox = \false; // optimize array calls if ($this->getAttribute('optimizable') && (!$env->isStrictVariables() || $this->getAttribute('ignore_strict_check')) && !$this->getAttribute('is_defined_test') && Template::ARRAY_CALL === $this->getAttribute('type')) { $var = '$' . $compiler->getVarName(); $compiler->raw('((' . $var . ' = ')->subcompile($this->getNode('node'))->raw(') && is_array(')->raw($var); if (!$env->hasExtension(SandboxExtension::class)) { $compiler->raw(') || ')->raw($var)->raw(' instanceof ArrayAccess ? (')->raw($var)->raw('[')->subcompile($this->getNode('attribute'))->raw('] ?? null) : null)'); return; } $arrayAccessSandbox = \true; $compiler->raw(') || ')->raw($var)->raw(' instanceof ArrayAccess && in_array(')->raw('get_class(' . $var . ')')->raw(', CoreExtension::ARRAY_LIKE_CLASSES, true) ? (')->raw($var)->raw('[')->subcompile($this->getNode('attribute'))->raw('] ?? null) : '); } $compiler->raw('CoreExtension::getAttribute($this->env, $this->source, '); if ($this->getAttribute('ignore_strict_check')) { $this->getNode('node')->setAttribute('ignore_strict_check', \true); } $compiler->subcompile($this->getNode('node'))->raw(', ')->subcompile($this->getNode('attribute')); if ($this->hasNode('arguments')) { $compiler->raw(', ')->subcompile($this->getNode('arguments')); } else { $compiler->raw(', []'); } $compiler->raw(', ')->repr($this->getAttribute('type'))->raw(', ')->repr($this->getAttribute('is_defined_test'))->raw(', ')->repr($this->getAttribute('ignore_strict_check'))->raw(', ')->repr($env->hasExtension(SandboxExtension::class))->raw(', ')->repr($this->getNode('node')->getTemplateLine())->raw(')'); if ($arrayAccessSandbox) { $compiler->raw(')'); } } } ParentExpression.php 0000644 00000002030 15253176377 0010601 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; /** * Represents a parent node. * * @author Fabien Potencier <fabien@symfony.com> */ class ParentExpression extends AbstractExpression { public function __construct(string $name, int $lineno, ?string $tag = null) { parent::__construct([], ['output' => \false, 'name' => $name], $lineno, $tag); } public function compile(Compiler $compiler) : void { if ($this->getAttribute('output')) { $compiler->addDebugInfo($this)->write('yield from $this->yieldParentBlock(')->string($this->getAttribute('name'))->raw(", \$context, \$blocks);\n"); } else { $compiler->raw('$this->renderParentBlock(')->string($this->getAttribute('name'))->raw(', $context, $blocks)'); } } } InlinePrint.php 0000644 00000001222 15253176377 0007525 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Node; /** * @internal */ final class InlinePrint extends AbstractExpression { public function __construct(Node $node, int $lineno) { parent::__construct(['node' => $node], [], $lineno); } public function compile(Compiler $compiler) : void { $compiler->raw('yield ')->subcompile($this->getNode('node')); } } TestExpression.php 0000644 00000002044 15253176377 0010274 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Node; class TestExpression extends CallExpression { public function __construct(Node $node, string $name, ?Node $arguments, int $lineno) { $nodes = ['node' => $node]; if (null !== $arguments) { $nodes['arguments'] = $arguments; } parent::__construct($nodes, ['name' => $name, 'type' => 'test'], $lineno); } public function compile(Compiler $compiler) : void { $test = $compiler->getEnvironment()->getTest($this->getAttribute('name')); $this->setAttribute('arguments', $test->getArguments()); $this->setAttribute('callable', $test->getCallable()); $this->setAttribute('is_variadic', $test->isVariadic()); $this->compileCallable($compiler); } } ConditionalExpression.php 0000644 00000002154 15253176377 0011622 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; class ConditionalExpression extends AbstractExpression { public function __construct(AbstractExpression $expr1, AbstractExpression $expr2, AbstractExpression $expr3, int $lineno) { parent::__construct(['expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno); } public function compile(Compiler $compiler) : void { // Ternary with no then uses Elvis operator if ($this->getNode('expr1') === $this->getNode('expr2')) { $compiler->raw('((')->subcompile($this->getNode('expr1'))->raw(') ?: (')->subcompile($this->getNode('expr3'))->raw('))'); } else { $compiler->raw('((')->subcompile($this->getNode('expr1'))->raw(') ? (')->subcompile($this->getNode('expr2'))->raw(') : (')->subcompile($this->getNode('expr3'))->raw('))'); } } } AssignNameExpression.php 0000644 00000000774 15253176377 0011412 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; class AssignNameExpression extends NameExpression { public function compile(Compiler $compiler) : void { $compiler->raw('$context[')->string($this->getAttribute('name'))->raw(']'); } } ArrayExpression.php 0000644 00000007434 15253176377 0010443 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; class ArrayExpression extends AbstractExpression { private $index; public function __construct(array $elements, int $lineno) { parent::__construct($elements, [], $lineno); $this->index = -1; foreach ($this->getKeyValuePairs() as $pair) { if ($pair['key'] instanceof ConstantExpression && \ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { $this->index = $pair['key']->getAttribute('value'); } } } public function getKeyValuePairs() : array { $pairs = []; foreach (\array_chunk($this->nodes, 2) as $pair) { $pairs[] = ['key' => $pair[0], 'value' => $pair[1]]; } return $pairs; } public function hasElement(AbstractExpression $key) : bool { foreach ($this->getKeyValuePairs() as $pair) { // we compare the string representation of the keys // to avoid comparing the line numbers which are not relevant here. if ((string) $key === (string) $pair['key']) { return \true; } } return \false; } public function addElement(AbstractExpression $value, ?AbstractExpression $key = null) : void { if (null === $key) { $key = new ConstantExpression(++$this->index, $value->getTemplateLine()); } \array_push($this->nodes, $key, $value); } public function compile(Compiler $compiler) : void { $keyValuePairs = $this->getKeyValuePairs(); $needsArrayMergeSpread = \PHP_VERSION_ID < 80100 && $this->hasSpreadItem($keyValuePairs); if ($needsArrayMergeSpread) { $compiler->raw('CoreExtension::merge('); } $compiler->raw('['); $first = \true; $reopenAfterMergeSpread = \false; $nextIndex = 0; foreach ($keyValuePairs as $pair) { if ($reopenAfterMergeSpread) { $compiler->raw(', ['); $reopenAfterMergeSpread = \false; } if ($needsArrayMergeSpread && $pair['value']->hasAttribute('spread')) { $compiler->raw('], ')->subcompile($pair['value']); $first = \true; $reopenAfterMergeSpread = \true; continue; } if (!$first) { $compiler->raw(', '); } $first = \false; if ($pair['value']->hasAttribute('spread') && !$needsArrayMergeSpread) { $compiler->raw('...')->subcompile($pair['value']); ++$nextIndex; } else { $key = $pair['key'] instanceof ConstantExpression ? $pair['key']->getAttribute('value') : null; if ($nextIndex !== $key) { if (\is_int($key)) { $nextIndex = $key + 1; } $compiler->subcompile($pair['key'])->raw(' => '); } else { ++$nextIndex; } $compiler->subcompile($pair['value']); } } if (!$reopenAfterMergeSpread) { $compiler->raw(']'); } if ($needsArrayMergeSpread) { $compiler->raw(')'); } } private function hasSpreadItem(array $pairs) : bool { foreach ($pairs as $pair) { if ($pair['value']->hasAttribute('spread')) { return \true; } } return \false; } } Unary/NegUnary.php 0000644 00000000712 15253176377 0010123 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Unary; use ElementorDeps\Twig\Compiler; class NegUnary extends AbstractUnary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('-'); } } Unary/PosUnary.php 0000644 00000000712 15253176377 0010153 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Unary; use ElementorDeps\Twig\Compiler; class PosUnary extends AbstractUnary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('+'); } } Unary/AbstractUnary.php 0000644 00000001521 15253176377 0011154 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Unary; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\AbstractExpression; use ElementorDeps\Twig\Node\Node; abstract class AbstractUnary extends AbstractExpression { public function __construct(Node $node, int $lineno) { parent::__construct(['node' => $node], [], $lineno); } public function compile(Compiler $compiler) : void { $compiler->raw(' '); $this->operator($compiler); $compiler->subcompile($this->getNode('node')); } public abstract function operator(Compiler $compiler) : Compiler; } Unary/NotUnary.php 0000644 00000000712 15253176377 0010152 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Unary; use ElementorDeps\Twig\Compiler; class NotUnary extends AbstractUnary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('!'); } } BlockReferenceExpression.php 0000644 00000004211 15253176377 0012224 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Node; /** * Represents a block call node. * * @author Fabien Potencier <fabien@symfony.com> */ class BlockReferenceExpression extends AbstractExpression { public function __construct(Node $name, ?Node $template, int $lineno, ?string $tag = null) { $nodes = ['name' => $name]; if (null !== $template) { $nodes['template'] = $template; } parent::__construct($nodes, ['is_defined_test' => \false, 'output' => \false], $lineno, $tag); } public function compile(Compiler $compiler) : void { if ($this->getAttribute('is_defined_test')) { $this->compileTemplateCall($compiler, 'hasBlock'); } else { if ($this->getAttribute('output')) { $compiler->addDebugInfo($this); $compiler->write('yield from '); $this->compileTemplateCall($compiler, 'yieldBlock')->raw(";\n"); } else { $this->compileTemplateCall($compiler, 'renderBlock'); } } } private function compileTemplateCall(Compiler $compiler, string $method) : Compiler { if (!$this->hasNode('template')) { $compiler->write('$this'); } else { $compiler->write('$this->loadTemplate(')->subcompile($this->getNode('template'))->raw(', ')->repr($this->getTemplateName())->raw(', ')->repr($this->getTemplateLine())->raw(')'); } $compiler->raw(\sprintf('->unwrap()->%s', $method)); return $this->compileBlockArguments($compiler); } private function compileBlockArguments(Compiler $compiler) : Compiler { $compiler->raw('(')->subcompile($this->getNode('name'))->raw(', $context'); if (!$this->hasNode('template')) { $compiler->raw(', $blocks'); } return $compiler->raw(')'); } } TempNameExpression.php 0000644 00000001142 15253176377 0011061 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; class TempNameExpression extends AbstractExpression { public function __construct(string $name, int $lineno) { parent::__construct([], ['name' => $name], $lineno); } public function compile(Compiler $compiler) : void { $compiler->raw('$_')->raw($this->getAttribute('name'))->raw('_'); } } Binary/LessBinary.php 0000644 00000001403 15253176377 0010572 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class LessBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { if (\PHP_VERSION_ID >= 80000) { parent::compile($compiler); return; } $compiler->raw('(-1 === CoreExtension::compare(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw('))'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('<'); } } Binary/BitwiseOrBinary.php 0000644 00000000723 15253176377 0011577 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class BitwiseOrBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('|'); } } Binary/AndBinary.php 0000644 00000000716 15253176377 0010374 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class AndBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('&&'); } } Binary/ConcatBinary.php 0000644 00000000720 15253176377 0011074 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class ConcatBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('.'); } } Binary/AddBinary.php 0000644 00000000715 15253176377 0010361 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class AddBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('+'); } } Binary/GreaterBinary.php 0000644 00000001405 15253176377 0011257 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class GreaterBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { if (\PHP_VERSION_ID >= 80000) { parent::compile($compiler); return; } $compiler->raw('(1 === CoreExtension::compare(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw('))'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('>'); } } Binary/InBinary.php 0000644 00000001214 15253176377 0010232 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class InBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $compiler->raw('CoreExtension::inFilter(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw(')'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('in'); } } Binary/RangeBinary.php 0000644 00000001175 15253176377 0010726 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class RangeBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $compiler->raw('range(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw(')'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('..'); } } Binary/MatchesBinary.php 0000644 00000001216 15253176377 0011252 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class MatchesBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $compiler->raw('CoreExtension::matches(')->subcompile($this->getNode('right'))->raw(', ')->subcompile($this->getNode('left'))->raw(')'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw(''); } } Binary/BitwiseAndBinary.php 0000644 00000000724 15253176377 0011722 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class BitwiseAndBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('&'); } } Binary/HasEveryBinary.php 0000644 00000001236 15253176377 0011416 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class HasEveryBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $compiler->raw('CoreExtension::arrayEvery($this->env, ')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw(')'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw(''); } } Binary/MulBinary.php 0000644 00000000715 15253176377 0010426 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class MulBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('*'); } } Binary/EndsWithBinary.php 0000644 00000001513 15253176377 0011413 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class EndsWithBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $left = $compiler->getVarName(); $right = $compiler->getVarName(); $compiler->raw(\sprintf('(is_string($%s = ', $left))->subcompile($this->getNode('left'))->raw(\sprintf(') && is_string($%s = ', $right))->subcompile($this->getNode('right'))->raw(\sprintf(') && str_ends_with($%1$s, $%2$s))', $left, $right)); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw(''); } } Binary/PowerBinary.php 0000644 00000000672 15253176377 0010767 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class PowerBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('**'); } } Binary/BitwiseXorBinary.php 0000644 00000000724 15253176377 0011770 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class BitwiseXorBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('^'); } } Binary/FloorDivBinary.php 0000644 00000001150 15253176377 0011407 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class FloorDivBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $compiler->raw('(int) floor('); parent::compile($compiler); $compiler->raw(')'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('/'); } } Binary/LessEqualBinary.php 0000644 00000001407 15253176377 0011566 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class LessEqualBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { if (\PHP_VERSION_ID >= 80000) { parent::compile($compiler); return; } $compiler->raw('(0 >= CoreExtension::compare(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw('))'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('<='); } } Binary/ModBinary.php 0000644 00000000715 15253176377 0010410 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class ModBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('%'); } } Binary/HasSomeBinary.php 0000644 00000001234 15253176377 0011225 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class HasSomeBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $compiler->raw('CoreExtension::arraySome($this->env, ')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw(')'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw(''); } } Binary/GreaterEqualBinary.php 0000644 00000001412 15253176377 0012245 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class GreaterEqualBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { if (\PHP_VERSION_ID >= 80000) { parent::compile($compiler); return; } $compiler->raw('(0 <= CoreExtension::compare(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw('))'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('>='); } } Binary/NotEqualBinary.php 0000644 00000001407 15253176377 0011420 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class NotEqualBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { if (\PHP_VERSION_ID >= 80000) { parent::compile($compiler); return; } $compiler->raw('(0 !== CoreExtension::compare(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw('))'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('!='); } } Binary/NotInBinary.php 0000644 00000001224 15253176377 0010714 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class NotInBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $compiler->raw('!CoreExtension::inFilter(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw(')'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('not in'); } } Binary/OrBinary.php 0000644 00000000715 15253176377 0010251 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class OrBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('||'); } } Binary/AbstractBinary.php 0000644 00000001666 15253176377 0011442 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\AbstractExpression; use ElementorDeps\Twig\Node\Node; abstract class AbstractBinary extends AbstractExpression { public function __construct(Node $left, Node $right, int $lineno) { parent::__construct(['left' => $left, 'right' => $right], [], $lineno); } public function compile(Compiler $compiler) : void { $compiler->raw('(')->subcompile($this->getNode('left'))->raw(' '); $this->operator($compiler); $compiler->raw(' ')->subcompile($this->getNode('right'))->raw(')'); } public abstract function operator(Compiler $compiler) : Compiler; } Binary/EqualBinary.php 0000644 00000001404 15253176377 0010734 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class EqualBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { if (\PHP_VERSION_ID >= 80000) { parent::compile($compiler); return; } $compiler->raw('(0 === CoreExtension::compare(')->subcompile($this->getNode('left'))->raw(', ')->subcompile($this->getNode('right'))->raw('))'); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw('=='); } } Binary/SubBinary.php 0000644 00000000715 15253176377 0010422 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class SubBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('-'); } } Binary/SpaceshipBinary.php 0000644 00000000677 15253176377 0011617 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class SpaceshipBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('<=>'); } } Binary/StartsWithBinary.php 0000644 00000001517 15253176377 0012006 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class StartsWithBinary extends AbstractBinary { public function compile(Compiler $compiler) : void { $left = $compiler->getVarName(); $right = $compiler->getVarName(); $compiler->raw(\sprintf('(is_string($%s = ', $left))->subcompile($this->getNode('left'))->raw(\sprintf(') && is_string($%s = ', $right))->subcompile($this->getNode('right'))->raw(\sprintf(') && str_starts_with($%1$s, $%2$s))', $left, $right)); } public function operator(Compiler $compiler) : Compiler { return $compiler->raw(''); } } Binary/DivBinary.php 0000644 00000000715 15253176377 0010413 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Binary; use ElementorDeps\Twig\Compiler; class DivBinary extends AbstractBinary { public function operator(Compiler $compiler) : Compiler { return $compiler->raw('/'); } } FunctionExpression.php 0000644 00000002705 15253176377 0011146 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Extension\CoreExtension; use ElementorDeps\Twig\Node\Node; class FunctionExpression extends CallExpression { public function __construct(string $name, Node $arguments, int $lineno) { parent::__construct(['arguments' => $arguments], ['name' => $name, 'type' => 'function', 'is_defined_test' => \false], $lineno); } public function compile(Compiler $compiler) { $name = $this->getAttribute('name'); $function = $compiler->getEnvironment()->getFunction($name); $this->setAttribute('needs_charset', $function->needsCharset()); $this->setAttribute('needs_environment', $function->needsEnvironment()); $this->setAttribute('needs_context', $function->needsContext()); $this->setAttribute('arguments', $function->getArguments()); $callable = $function->getCallable(); if ('constant' === $name && $this->getAttribute('is_defined_test')) { $callable = [CoreExtension::class, 'constantIsDefined']; } $this->setAttribute('callable', $callable); $this->setAttribute('is_variadic', $function->isVariadic()); $this->compileCallable($compiler); } } CallExpression.php 0000644 00000027147 15253176377 0010243 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Error\SyntaxError; use ElementorDeps\Twig\Extension\ExtensionInterface; use ElementorDeps\Twig\Node\Node; use ElementorDeps\Twig\Util\ReflectionCallable; abstract class CallExpression extends AbstractExpression { private $reflector = null; protected function compileCallable(Compiler $compiler) { $callable = $this->getAttribute('callable'); if (\is_string($callable) && !\str_contains($callable, '::')) { $compiler->raw($callable); } else { $rc = $this->reflectCallable($callable); $r = $rc->getReflector(); $callable = $rc->getCallable(); if (\is_string($callable)) { $compiler->raw($callable); } elseif (\is_array($callable) && \is_string($callable[0])) { if (!$r instanceof \ReflectionMethod || $r->isStatic()) { $compiler->raw(\sprintf('%s::%s', $callable[0], $callable[1])); } else { $compiler->raw(\sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); } } elseif (\is_array($callable) && $callable[0] instanceof ExtensionInterface) { $class = \get_class($callable[0]); if (!$compiler->getEnvironment()->hasExtension($class)) { // Compile a non-optimized call to trigger a \Twig\Error\RuntimeError, which cannot be a compile-time error $compiler->raw(\sprintf('$this->env->getExtension(\'%s\')', $class)); } else { $compiler->raw(\sprintf('$this->extensions[\'%s\']', \ltrim($class, '\\'))); } $compiler->raw(\sprintf('->%s', $callable[1])); } else { $compiler->raw(\sprintf('$this->env->get%s(\'%s\')->getCallable()', \ucfirst($this->getAttribute('type')), $this->getAttribute('name'))); } } $this->compileArguments($compiler); } protected function compileArguments(Compiler $compiler, $isArray = \false) : void { if (\func_num_args() >= 2) { trigger_deprecation('twig/twig', '3.11', 'Passing a second argument to "%s()" is deprecated.', __METHOD__); } $compiler->raw($isArray ? '[' : '('); $first = \true; if ($this->hasAttribute('needs_charset') && $this->getAttribute('needs_charset')) { $compiler->raw('$this->env->getCharset()'); $first = \false; } if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { if (!$first) { $compiler->raw(', '); } $compiler->raw('$this->env'); $first = \false; } if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { if (!$first) { $compiler->raw(', '); } $compiler->raw('$context'); $first = \false; } if ($this->hasAttribute('arguments')) { foreach ($this->getAttribute('arguments') as $argument) { if (!$first) { $compiler->raw(', '); } $compiler->string($argument); $first = \false; } } if ($this->hasNode('node')) { if (!$first) { $compiler->raw(', '); } $compiler->subcompile($this->getNode('node')); $first = \false; } if ($this->hasNode('arguments')) { $callable = $this->getAttribute('callable'); $arguments = $this->getArguments($callable, $this->getNode('arguments')); foreach ($arguments as $node) { if (!$first) { $compiler->raw(', '); } $compiler->subcompile($node); $first = \false; } } $compiler->raw($isArray ? ']' : ')'); } protected function getArguments($callable, $arguments) { $callType = $this->getAttribute('type'); $callName = $this->getAttribute('name'); $parameters = []; $named = \false; foreach ($arguments as $name => $node) { if (!\is_int($name)) { $named = \true; $name = $this->normalizeName($name); } elseif ($named) { throw new SyntaxError(\sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); } $parameters[$name] = $node; } $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic'); if (!$named && !$isVariadic) { return $parameters; } if (!$callable) { if ($named) { $message = \sprintf('Named arguments are not supported for %s "%s".', $callType, $callName); } else { $message = \sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName); } throw new \LogicException($message); } [$callableParameters, $isPhpVariadic] = $this->getCallableParameters($callable, $isVariadic); $arguments = []; $names = []; $missingArguments = []; $optionalArguments = []; $pos = 0; foreach ($callableParameters as $callableParameter) { $name = $this->normalizeName($callableParameter->name); if (\PHP_VERSION_ID >= 80000 && 'range' === $callable) { if ('start' === $name) { $name = 'low'; } elseif ('end' === $name) { $name = 'high'; } } $names[] = $name; if (\array_key_exists($name, $parameters)) { if (\array_key_exists($pos, $parameters)) { throw new SyntaxError(\sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); } if (\count($missingArguments)) { throw new SyntaxError(\sprintf('Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".', $name, $callType, $callName, \implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', \implode('", "', $missingArguments)), $this->getTemplateLine(), $this->getSourceContext()); } $arguments = \array_merge($arguments, $optionalArguments); $arguments[] = $parameters[$name]; unset($parameters[$name]); $optionalArguments = []; } elseif (\array_key_exists($pos, $parameters)) { $arguments = \array_merge($arguments, $optionalArguments); $arguments[] = $parameters[$pos]; unset($parameters[$pos]); $optionalArguments = []; ++$pos; } elseif ($callableParameter->isDefaultValueAvailable()) { $optionalArguments[] = new ConstantExpression($callableParameter->getDefaultValue(), -1); } elseif ($callableParameter->isOptional()) { if (empty($parameters)) { break; } else { $missingArguments[] = $name; } } else { throw new SyntaxError(\sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext()); } } if ($isVariadic) { $arbitraryArguments = $isPhpVariadic ? new VariadicExpression([], -1) : new ArrayExpression([], -1); foreach ($parameters as $key => $value) { if (\is_int($key)) { $arbitraryArguments->addElement($value); } else { $arbitraryArguments->addElement($value, new ConstantExpression($key, -1)); } unset($parameters[$key]); } if ($arbitraryArguments->count()) { $arguments = \array_merge($arguments, $optionalArguments); $arguments[] = $arbitraryArguments; } } if (!empty($parameters)) { $unknownParameter = null; foreach ($parameters as $parameter) { if ($parameter instanceof Node) { $unknownParameter = $parameter; break; } } throw new SyntaxError(\sprintf('Unknown argument%s "%s" for %s "%s(%s)".', \count($parameters) > 1 ? 's' : '', \implode('", "', \array_keys($parameters)), $callType, $callName, \implode(', ', $names)), $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine(), $unknownParameter ? $unknownParameter->getSourceContext() : $this->getSourceContext()); } return $arguments; } protected function normalizeName(string $name) : string { return \strtolower(\preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name)); } private function getCallableParameters($callable, bool $isVariadic) : array { $rc = $this->reflectCallable($callable); $r = $rc->getReflector(); $callableName = $rc->getName(); $parameters = $r->getParameters(); if ($this->hasNode('node')) { \array_shift($parameters); } if ($this->hasAttribute('needs_charset') && $this->getAttribute('needs_charset')) { \array_shift($parameters); } if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) { \array_shift($parameters); } if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) { \array_shift($parameters); } if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) { foreach ($this->getAttribute('arguments') as $argument) { \array_shift($parameters); } } $isPhpVariadic = \false; if ($isVariadic) { $argument = \end($parameters); $isArray = $argument && $argument->hasType() && $argument->getType() instanceof \ReflectionNamedType && 'array' === $argument->getType()->getName(); if ($isArray && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) { \array_pop($parameters); } elseif ($argument && $argument->isVariadic()) { \array_pop($parameters); $isPhpVariadic = \true; } else { throw new \LogicException(\sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name'))); } } return [$parameters, $isPhpVariadic]; } private function reflectCallable($callable) : ReflectionCallable { if (!$this->reflector) { $this->reflector = new ReflectionCallable($callable, $this->getAttribute('type'), $this->getAttribute('name')); } return $this->reflector; } } ConstantExpression.php 0000644 00000001163 15253176377 0011147 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; /** * @final */ class ConstantExpression extends AbstractExpression { public function __construct($value, int $lineno) { parent::__construct([], ['value' => $value], $lineno); } public function compile(Compiler $compiler) : void { $compiler->repr($this->getAttribute('value')); } } ArrowFunctionExpression.php 0000644 00000002507 15253176377 0012161 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Node; /** * Represents an arrow function. * * @author Fabien Potencier <fabien@symfony.com> */ class ArrowFunctionExpression extends AbstractExpression { public function __construct(AbstractExpression $expr, Node $names, $lineno, $tag = null) { parent::__construct(['expr' => $expr, 'names' => $names], [], $lineno, $tag); } public function compile(Compiler $compiler) : void { $compiler->addDebugInfo($this)->raw('function ('); foreach ($this->getNode('names') as $i => $name) { if ($i) { $compiler->raw(', '); } $compiler->raw('$__')->raw($name->getAttribute('name'))->raw('__'); } $compiler->raw(') use ($context, $macros) { '); foreach ($this->getNode('names') as $name) { $compiler->raw('$context["')->raw($name->getAttribute('name'))->raw('"] = $__')->raw($name->getAttribute('name'))->raw('__; '); } $compiler->raw('return ')->subcompile($this->getNode('expr'))->raw('; }'); } } NameExpression.php 0000644 00000005340 15253176377 0010237 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; class NameExpression extends AbstractExpression { private $specialVars = ['_self' => '$this->getTemplateName()', '_context' => '$context', '_charset' => '$this->env->getCharset()']; public function __construct(string $name, int $lineno) { parent::__construct([], ['name' => $name, 'is_defined_test' => \false, 'ignore_strict_check' => \false, 'always_defined' => \false], $lineno); } public function compile(Compiler $compiler) : void { $name = $this->getAttribute('name'); $compiler->addDebugInfo($this); if ($this->getAttribute('is_defined_test')) { if (isset($this->specialVars[$name])) { $compiler->repr(\true); } elseif (\PHP_VERSION_ID >= 70400) { $compiler->raw('array_key_exists(')->string($name)->raw(', $context)'); } else { $compiler->raw('(isset($context[')->string($name)->raw(']) || array_key_exists(')->string($name)->raw(', $context))'); } } elseif (isset($this->specialVars[$name])) { $compiler->raw($this->specialVars[$name]); } elseif ($this->getAttribute('always_defined')) { $compiler->raw('$context[')->string($name)->raw(']'); } else { if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) { $compiler->raw('($context[')->string($name)->raw('] ?? null)'); } else { $compiler->raw('(isset($context[')->string($name)->raw(']) || array_key_exists(')->string($name)->raw(', $context) ? $context[')->string($name)->raw('] : (function () { throw new RuntimeError(\'Variable ')->string($name)->raw(' does not exist.\', ')->repr($this->lineno)->raw(', $this->source); })()')->raw(')'); } } } /** * @deprecated since Twig 3.11 (to be removed in 4.0) */ public function isSpecial() { trigger_deprecation('twig/twig', '3.11', 'The "%s()" method is deprecated and will be removed in Twig 4.0.', __METHOD__); return isset($this->specialVars[$this->getAttribute('name')]); } /** * @deprecated since Twig 3.11 (to be removed in 4.0) */ public function isSimple() { trigger_deprecation('twig/twig', '3.11', 'The "%s()" method is deprecated and will be removed in Twig 4.0.', __METHOD__); return !$this->isSpecial() && !$this->getAttribute('is_defined_test'); } } Filter/RawFilter.php 0000644 00000002207 15253176377 0010422 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Filter; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\ConstantExpression; use ElementorDeps\Twig\Node\Expression\FilterExpression; use ElementorDeps\Twig\Node\Node; /** * @author Fabien Potencier <fabien@symfony.com> */ class RawFilter extends FilterExpression { public function __construct(Node $node, ?ConstantExpression $filterName = null, ?Node $arguments = null, int $lineno = 0, ?string $tag = null) { if (null === $filterName) { $filterName = new ConstantExpression('raw', $node->getTemplateLine()); } if (null === $arguments) { $arguments = new Node(); } parent::__construct($node, $filterName, $arguments, $lineno ?: $node->getTemplateLine(), $tag ?: $node->getNodeTag()); } public function compile(Compiler $compiler) : void { $compiler->subcompile($this->getNode('node')); } } Filter/DefaultFilter.php 0000644 00000003573 15253176377 0011264 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression\Filter; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Expression\ConditionalExpression; use ElementorDeps\Twig\Node\Expression\ConstantExpression; use ElementorDeps\Twig\Node\Expression\FilterExpression; use ElementorDeps\Twig\Node\Expression\GetAttrExpression; use ElementorDeps\Twig\Node\Expression\NameExpression; use ElementorDeps\Twig\Node\Expression\Test\DefinedTest; use ElementorDeps\Twig\Node\Node; /** * Returns the value or the default value when it is undefined or empty. * * {{ var.foo|default('foo item on var is not defined') }} * * @author Fabien Potencier <fabien@symfony.com> */ class DefaultFilter extends FilterExpression { public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, ?string $tag = null) { $default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); if ('default' === $filterName->getAttribute('value') && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) { $test = new DefinedTest(clone $node, 'defined', new Node(), $node->getTemplateLine()); $false = \count($arguments) ? $arguments->getNode('0') : new ConstantExpression('', $node->getTemplateLine()); $node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine()); } else { $node = $default; } parent::__construct($node, $filterName, $arguments, $lineno, $tag); } public function compile(Compiler $compiler) : void { $compiler->subcompile($this->getNode('node')); } } VariadicExpression.php 0000644 00000000724 15253176377 0011102 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; class VariadicExpression extends ArrayExpression { public function compile(Compiler $compiler) : void { $compiler->raw('...'); parent::compile($compiler); } } FilterExpression.php 0000644 00000003542 15253176377 0010606 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * (c) Armin Ronacher * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; use ElementorDeps\Twig\Node\Node; class FilterExpression extends CallExpression { public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, ?string $tag = null) { parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], ['name' => $filterName->getAttribute('value'), 'type' => 'filter'], $lineno, $tag); } public function compile(Compiler $compiler) : void { $name = $this->getNode('filter')->getAttribute('value'); if ($name !== $this->getAttribute('name')) { trigger_deprecation('twig/twig', '3.11', 'Changing the value of a "filter" node in a NodeVisitor class is not supported anymore.'); $this->setAttribute('name', $name); } if ('raw' === $name) { trigger_deprecation('twig/twig', '3.11', 'Creating the "raw" filter via "FilterExpression" is deprecated; use "RawFilter" instead.'); $compiler->subcompile($this->getNode('node')); return; } $filter = $compiler->getEnvironment()->getFilter($name); $this->setAttribute('needs_charset', $filter->needsCharset()); $this->setAttribute('needs_environment', $filter->needsEnvironment()); $this->setAttribute('needs_context', $filter->needsContext()); $this->setAttribute('arguments', $filter->getArguments()); $this->setAttribute('callable', $filter->getCallable()); $this->setAttribute('is_variadic', $filter->isVariadic()); $this->compileCallable($compiler); } } MethodCallExpression.php 0000644 00000003200 15253176377 0011364 0 ustar 00 <?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ElementorDeps\Twig\Node\Expression; use ElementorDeps\Twig\Compiler; class MethodCallExpression extends AbstractExpression { public function __construct(AbstractExpression $node, string $method, ArrayExpression $arguments, int $lineno) { parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => \false, 'is_defined_test' => \false], $lineno); if ($node instanceof NameExpression) { $node->setAttribute('always_defined', \true); } } public function compile(Compiler $compiler) : void { if ($this->getAttribute('is_defined_test')) { $compiler->raw('method_exists($macros[')->repr($this->getNode('node')->getAttribute('name'))->raw('], ')->repr($this->getAttribute('method'))->raw(')'); return; } $compiler->raw('CoreExtension::callMacro($macros[')->repr($this->getNode('node')->getAttribute('name'))->raw('], ')->repr($this->getAttribute('method'))->raw(', ['); $first = \true; /** @var ArrayExpression */ $args = $this->getNode('arguments'); foreach ($args->getKeyValuePairs() as $pair) { if (!$first) { $compiler->raw(', '); } $first = \false; $compiler->subcompile($pair['value']); } $compiler->raw('], ')->repr($this->getTemplateLine())->raw(', $context, $this->getSourceContext())'); } }
dvadf
dvadf
| ver. 1.4 |
Github
|
.
| PHP 7.3.33 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings