/** * Parses "10x @user*", "<randomNumber(0, 10)x @user<{param}>*", etc. * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) : DynamicArrayValue { parent::parse($token); if (1 !== preg_match(self::REGEX, $token->getValue(), $matches)) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } return new DynamicArrayValue((int) $this->parser->parse($matches['quantifier']), $this->parser->parse($matches['elements'])); }
/** * Parses expressions such as '60%? foo: bar'. * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) : OptionalValue { parent::parse($token); if (1 !== preg_match(self::REGEX, $token->getValue(), $matches)) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } return new OptionalValue($this->parser->parse($matches['quantifier']), $this->parser->parse(trim($matches['first_member'])), array_key_exists('second_member', $matches) ? $this->parser->parse($matches['second_member']) : null); }
/** * Parses '<{paramKey}>', '<{nested_<{param}>}>'. * * {@inheritdoc} */ public function parse(Token $token) : array { parent::parse($token); $value = $token->getValue(); try { $elements = substr($value, 1, strlen($value) - 2); return $this->parseElements($this->parser, $elements); } catch (\TypeError $error) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $error); } }
/** * Parses tokens values like "@user->username". * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) : FixturePropertyValue { parent::parse($token); $explodedValue = explode('->', $token->getValue()); if (count($explodedValue) !== 2) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } $reference = $this->parser->parse($explodedValue[0]); if (false === $reference instanceof ValueInterface) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } return new FixturePropertyValue($reference, $explodedValue[1]); }
/** * Parses tokens values like "@user->getUserName()". * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) : FixtureMethodCallValue { parent::parse($token); $explodedValue = explode('->', $token->getValue()); if (count($explodedValue) !== 2) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } $reference = $this->parser->parse($explodedValue[0]); $method = $this->parser->parse(sprintf('<%s>', $explodedValue[1])); if ($reference instanceof FixtureReferenceValue && $method instanceof FunctionCallValue) { return new FixtureMethodCallValue($reference, $method); } throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); }
/** * Parses expressions such as "@username->getName()". * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) { parent::parse($token); $values = preg_split('/->/', $token->getValue()); if (2 !== count($values)) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } $fixture = $this->parser->parse($values[0]); $method = $this->parser->parse(sprintf('<%s>', $values[1])); try { return new FixtureMethodCallValue($fixture, $method); } catch (\TypeError $exception) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $exception); } }
/** * Parses expressions such as '<foo()>', '<foo(arg1, arg2)>'. * * {@inheritdoc} * * @throws ParseException */ 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); }
/** * Handle cases like '<f()> <g()>' by trying to break down the token. * * {@inheritdoc} * * @throws LexException * @TODO: handle redundant ListValue tokens * * @return FunctionCallValue|ListValue */ public function parse(Token $token) { parent::parse($token); $split = preg_split(self::REGEX, $token->getValue(), 2, PREG_SPLIT_DELIM_CAPTURE + PREG_SPLIT_NO_EMPTY); $splitSize = count($split); if (1 === $splitSize) { return $this->functionTokenParser->parse($token); } if (3 !== count($split) && 4 !== count($split)) { throw ExpressionLanguageExceptionFactory::createForCouldNotLexValue($token->getValue()); } $values = [$this->parser->parse($split[0] . $split[1])]; if (3 === $splitSize) { $values[] = $this->parser->parse('<' . $split[2]); } if (4 === $splitSize) { $values[] = $this->parser->parse($split[2]); $values[] = $this->parser->parse('<' . $split[3]); } return $this->mergeValues($values); }