[ExpressionLanguage] Add more parameter types.
This commit is contained in:
parent
90e3da4edd
commit
e378a7a42d
@ -28,7 +28,7 @@ class Compiler implements ResetInterface
|
|||||||
$this->functions = $functions;
|
$this->functions = $functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFunction($name)
|
public function getFunction(string $name)
|
||||||
{
|
{
|
||||||
return $this->functions[$name];
|
return $this->functions[$name];
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class ArrayNode extends Node
|
|||||||
$compiler->raw(']');
|
$compiler->raw(']');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($this->getKeyValuePairs() as $pair) {
|
foreach ($this->getKeyValuePairs() as $pair) {
|
||||||
|
@ -84,7 +84,7 @@ class BinaryNode extends Node
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
$operator = $this->attributes['operator'];
|
$operator = $this->attributes['operator'];
|
||||||
$left = $this->nodes['left']->evaluate($functions, $values);
|
$left = $this->nodes['left']->evaluate($functions, $values);
|
||||||
|
@ -40,7 +40,7 @@ class ConditionalNode extends Node
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
if ($this->nodes['expr1']->evaluate($functions, $values)) {
|
if ($this->nodes['expr1']->evaluate($functions, $values)) {
|
||||||
return $this->nodes['expr2']->evaluate($functions, $values);
|
return $this->nodes['expr2']->evaluate($functions, $values);
|
||||||
|
@ -36,7 +36,7 @@ class ConstantNode extends Node
|
|||||||
$compiler->repr($this->attributes['value']);
|
$compiler->repr($this->attributes['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
return $this->attributes['value'];
|
return $this->attributes['value'];
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class FunctionNode extends Node
|
|||||||
$compiler->raw($function['compiler'](...$arguments));
|
$compiler->raw($function['compiler'](...$arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
$arguments = [$values];
|
$arguments = [$values];
|
||||||
foreach ($this->nodes['arguments']->nodes as $node) {
|
foreach ($this->nodes['arguments']->nodes as $node) {
|
||||||
|
@ -64,7 +64,7 @@ class GetAttrNode extends Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
switch ($this->attributes['type']) {
|
switch ($this->attributes['type']) {
|
||||||
case self::PROPERTY_CALL:
|
case self::PROPERTY_CALL:
|
||||||
|
@ -33,7 +33,7 @@ class NameNode extends Node
|
|||||||
$compiler->raw('$'.$this->attributes['name']);
|
$compiler->raw('$'.$this->attributes['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
return $values[$this->attributes['name']];
|
return $values[$this->attributes['name']];
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ class Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
$results = [];
|
$results = [];
|
||||||
foreach ($this->nodes as $node) {
|
foreach ($this->nodes as $node) {
|
||||||
@ -90,7 +90,7 @@ class Node
|
|||||||
return $dump;
|
return $dump;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function dumpString($value)
|
protected function dumpString(string $value)
|
||||||
{
|
{
|
||||||
return sprintf('"%s"', addcslashes($value, "\0\t\"\\"));
|
return sprintf('"%s"', addcslashes($value, "\0\t\"\\"));
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class UnaryNode extends Node
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function evaluate($functions, $values)
|
public function evaluate(array $functions, array $values)
|
||||||
{
|
{
|
||||||
$value = $this->nodes['node']->evaluate($functions, $values);
|
$value = $this->nodes['node']->evaluate($functions, $values);
|
||||||
switch ($this->attributes['operator']) {
|
switch ($this->attributes['operator']) {
|
||||||
|
@ -146,7 +146,7 @@ class Parser
|
|||||||
return $this->parsePrimaryExpression();
|
return $this->parsePrimaryExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseConditionalExpression($expr)
|
protected function parseConditionalExpression(Node\Node $expr)
|
||||||
{
|
{
|
||||||
while ($this->stream->current->test(Token::PUNCTUATION_TYPE, '?')) {
|
while ($this->stream->current->test(Token::PUNCTUATION_TYPE, '?')) {
|
||||||
$this->stream->next();
|
$this->stream->next();
|
||||||
@ -299,7 +299,7 @@ class Parser
|
|||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parsePostfixExpression($node)
|
public function parsePostfixExpression(Node\Node $node)
|
||||||
{
|
{
|
||||||
$token = $this->stream->current;
|
$token = $this->stream->current;
|
||||||
while (Token::PUNCTUATION_TYPE == $token->type) {
|
while (Token::PUNCTUATION_TYPE == $token->type) {
|
||||||
|
Reference in New Issue
Block a user