Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+28 -11
View File
@@ -12,6 +12,7 @@
namespace Symfony\Component\ExpressionLanguage\Node;
use Symfony\Component\ExpressionLanguage\Compiler;
use Symfony\Component\ExpressionLanguage\SyntaxError;
/**
* @author Fabien Potencier <fabien@symfony.com>
@@ -20,20 +21,20 @@ use Symfony\Component\ExpressionLanguage\Compiler;
*/
class BinaryNode extends Node
{
private static $operators = [
private const OPERATORS = [
'~' => '.',
'and' => '&&',
'or' => '||',
];
private static $functions = [
private const FUNCTIONS = [
'**' => 'pow',
'..' => 'range',
'in' => 'in_array',
'not in' => '!in_array',
];
public function __construct($operator, Node $left, Node $right)
public function __construct(string $operator, Node $left, Node $right)
{
parent::__construct(
['left' => $left, 'right' => $right],
@@ -46,8 +47,12 @@ class BinaryNode extends Node
$operator = $this->attributes['operator'];
if ('matches' == $operator) {
if ($this->nodes['right'] instanceof ConstantNode) {
$this->evaluateMatches($this->nodes['right']->evaluate([], []), '');
}
$compiler
->raw('preg_match(')
->raw('(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })(')
->compile($this->nodes['right'])
->raw(', ')
->compile($this->nodes['left'])
@@ -57,9 +62,9 @@ class BinaryNode extends Node
return;
}
if (isset(self::$functions[$operator])) {
if (isset(self::FUNCTIONS[$operator])) {
$compiler
->raw(sprintf('%s(', self::$functions[$operator]))
->raw(sprintf('%s(', self::FUNCTIONS[$operator]))
->compile($this->nodes['left'])
->raw(', ')
->compile($this->nodes['right'])
@@ -69,8 +74,8 @@ class BinaryNode extends Node
return;
}
if (isset(self::$operators[$operator])) {
$operator = self::$operators[$operator];
if (isset(self::OPERATORS[$operator])) {
$operator = self::OPERATORS[$operator];
}
$compiler
@@ -89,13 +94,13 @@ class BinaryNode extends Node
$operator = $this->attributes['operator'];
$left = $this->nodes['left']->evaluate($functions, $values);
if (isset(self::$functions[$operator])) {
if (isset(self::FUNCTIONS[$operator])) {
$right = $this->nodes['right']->evaluate($functions, $values);
if ('not in' === $operator) {
return !\in_array($left, $right);
}
$f = self::$functions[$operator];
$f = self::FUNCTIONS[$operator];
return $f($left, $right);
}
@@ -159,7 +164,7 @@ class BinaryNode extends Node
return $left % $right;
case 'matches':
return preg_match($right, $left);
return $this->evaluateMatches($right, $left);
}
}
@@ -167,4 +172,16 @@ class BinaryNode extends Node
{
return ['(', $this->nodes['left'], ' '.$this->attributes['operator'].' ', $this->nodes['right'], ')'];
}
private function evaluateMatches(string $regexp, ?string $str): int
{
set_error_handler(function ($t, $m) use ($regexp) {
throw new SyntaxError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
});
try {
return preg_match($regexp, (string) $str);
} finally {
restore_error_handler();
}
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ class ConstantNode extends Node
{
private $isIdentifier;
public function __construct($value, $isIdentifier = false)
public function __construct($value, bool $isIdentifier = false)
{
$this->isIdentifier = $isIdentifier;
parent::__construct(
+3 -3
View File
@@ -20,7 +20,7 @@ use Symfony\Component\ExpressionLanguage\Compiler;
*/
class FunctionNode extends Node
{
public function __construct($name, Node $arguments)
public function __construct(string $name, Node $arguments)
{
parent::__construct(
['arguments' => $arguments],
@@ -37,7 +37,7 @@ class FunctionNode extends Node
$function = $compiler->getFunction($this->attributes['name']);
$compiler->raw(\call_user_func_array($function['compiler'], $arguments));
$compiler->raw($function['compiler'](...$arguments));
}
public function evaluate($functions, $values)
@@ -47,7 +47,7 @@ class FunctionNode extends Node
$arguments[] = $node->evaluate($functions, $values);
}
return \call_user_func_array($functions[$this->attributes['name']]['evaluator'], $arguments);
return $functions[$this->attributes['name']]['evaluator'](...$arguments);
}
public function toArray()
+5 -11
View File
@@ -20,11 +20,11 @@ use Symfony\Component\ExpressionLanguage\Compiler;
*/
class GetAttrNode extends Node
{
const PROPERTY_CALL = 1;
const METHOD_CALL = 2;
const ARRAY_CALL = 3;
public const PROPERTY_CALL = 1;
public const METHOD_CALL = 2;
public const ARRAY_CALL = 3;
public function __construct(Node $node, Node $attribute, ArrayNode $arguments, $type)
public function __construct(Node $node, Node $attribute, ArrayNode $arguments, int $type)
{
parent::__construct(
['node' => $node, 'attribute' => $attribute, 'arguments' => $arguments],
@@ -86,13 +86,7 @@ class GetAttrNode extends Node
throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], \get_class($obj)));
}
$arguments = $this->nodes['arguments']->evaluate($functions, $values);
if (\PHP_VERSION_ID >= 80000) {
$arguments = array_values($arguments);
}
return \call_user_func_array($toCall, $arguments);
return $toCall(...array_values($this->nodes['arguments']->evaluate($functions, $values)));
case self::ARRAY_CALL:
$array = $this->nodes['node']->evaluate($functions, $values);
+1 -1
View File
@@ -20,7 +20,7 @@ use Symfony\Component\ExpressionLanguage\Compiler;
*/
class NameNode extends Node
{
public function __construct($name)
public function __construct(string $name)
{
parent::__construct(
[],
+4 -1
View File
@@ -33,6 +33,9 @@ class Node
$this->attributes = $attributes;
}
/**
* @return string
*/
public function __toString()
{
$attributes = [];
@@ -84,7 +87,7 @@ class Node
$dump = '';
foreach ($this->toArray() as $v) {
$dump .= is_scalar($v) ? $v : $v->dump();
$dump .= \is_scalar($v) ? $v : $v->dump();
}
return $dump;
+4 -4
View File
@@ -20,14 +20,14 @@ use Symfony\Component\ExpressionLanguage\Compiler;
*/
class UnaryNode extends Node
{
private static $operators = [
private const OPERATORS = [
'!' => '!',
'not' => '!',
'+' => '+',
'-' => '-',
];
public function __construct($operator, Node $node)
public function __construct(string $operator, Node $node)
{
parent::__construct(
['node' => $node],
@@ -39,7 +39,7 @@ class UnaryNode extends Node
{
$compiler
->raw('(')
->raw(self::$operators[$this->attributes['operator']])
->raw(self::OPERATORS[$this->attributes['operator']])
->compile($this->nodes['node'])
->raw(')')
;
@@ -59,7 +59,7 @@ class UnaryNode extends Node
return $value;
}
public function toArray()
public function toArray(): array
{
return ['(', $this->attributes['operator'].' ', $this->nodes['node'], ')'];
}