[ExpressionLanguage] Add more parameter types.

This commit is contained in:
Alexander M. Turek 2019-08-16 01:47:11 +02:00
parent 90e3da4edd
commit e378a7a42d
11 changed files with 13 additions and 13 deletions

View File

@ -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];
} }

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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'];
} }

View File

@ -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) {

View File

@ -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:

View File

@ -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']];
} }

View File

@ -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\"\\"));
} }

View File

@ -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']) {

View File

@ -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) {