Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\TokenParser\Chainable\FunctionTokenParser::parse PHP Метод

parse() публичный Метод

public parse ( Token $token ) : FunctionCallValue
$token Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Token
Результат Nelmio\Alice\Definition\Value\FunctionCallValue
    public function parse(Token $token) : FunctionCallValue
    {
        parent::parse($token);
        if (1 !== preg_match(self::REGEX, $token->getValue(), $matches)) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }
        $function = $matches['function'];
        if ('identity' === $function) {
            $arguments = [new EvaluatedValue($matches['arguments'])];
        } elseif ('current' === $function) {
            $arguments = [new ValueForCurrentValue()];
        } else {
            $arguments = $this->parseArguments($this->parser, trim($matches['arguments']));
        }
        return new FunctionCallValue($function, $arguments);
    }

Usage Example

Пример #1
0
 public function testCanParseArgumentsForCurrentValue()
 {
     // Arguments should be discarded
     $token = new Token('<current( arg0 , arg1 )>', new TokenType(TokenType::FUNCTION_TYPE));
     $expected = new FunctionCallValue('current', [new ValueForCurrentValue()]);
     $parser = new FunctionTokenParser(new FakeParser());
     $actual = $parser->parse($token);
     $this->assertEquals($expected, $actual);
     $this->assertInstanceOf(ValueForCurrentValue::class, $actual->getArguments()[0]);
 }