/** * Parses expressions such as '$username'. * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) { try { return new VariableValue(substr($token->getValue(), 1)); } catch (\TypeError $error) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $error); } }
/** * Parses '<<', '@@'... * * {@inheritdoc} */ public function parse(Token $token) : string { $value = $token->getValue(); if ('' === $value) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } return $this->tokenizer->detokenize(substr($value, 1)); }
/** * Parses expressions such as "@user". * * {@inheritdoc} */ public function parse(Token $token) : FixtureReferenceValue { $value = $token->getValue(); try { return new FixtureReferenceValue(substr($value, 1)); } catch (\InvalidArgumentException $exception) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $exception); } }
/** * Parses expressions such as '$username'. * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) { $value = $token->getValue(); $fixtureId = substr($value, 1, strlen($value) - 2); if (false === $fixtureId) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } return FixtureMatchReferenceValue::createWildcardReference($fixtureId); }
/** * Parses '<{paramKey}>', '<{nested_<{param}>}>', etc. * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) : ParameterValue { $value = $token->getValue(); try { $paramKey = substr($value, 2, strlen($value) - 4); return new ParameterValue($paramKey); } catch (\TypeError $error) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $error); } }
/** * @param Token $token * * @throws ParseException * * @return RangeName * * @example * "@user{1..10}" => new RangeName('user', 1, 10) */ private function buildRange(Token $token) : RangeName { $matches = []; $name = substr($token->getValue(), 1); if (1 !== preg_match(self::REGEX, (string) $name, $matches)) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } $reference = str_replace(sprintf('{%s}', $matches['range']), $this->token, $name); return new RangeName($reference, (int) $matches['from'], (int) $matches['to']); }
/** * @param Token $token * * @throws ParseException * * @return string[] * * @example * "@user_{alice, bob}" => ['user_alice', 'user_bob'] */ private function buildReferences(Token $token) : array { $matches = []; $name = (string) substr($token->getValue(), 1); if (1 !== preg_match(self::REGEX, $name, $matches)) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token); } $listElements = preg_split('/\\s*,\\s*/', $matches['list']); $references = []; foreach ($listElements as $element) { $fixtureId = str_replace(sprintf('{%s}', $matches['list']), $element, $name); $references[] = new FixtureReferenceValue($fixtureId); } return $references; }
/** * @inheritdoc */ public function canParse(Token $token) : bool { return $token->getType() === TokenType::DYNAMIC_ARRAY_TYPE; }
/** * @inheritdoc */ public function canParse(Token $token) : bool { return $token->getType() === TokenType::FUNCTION_TYPE; }
/** * @inheritdoc */ public function canParse(Token $token) : bool { return $token->getType() === TokenType::PROPERTY_REFERENCE_TYPE; }
/** * Parses expressions such as '<(something)>'. * * {@inheritdoc} * * @throws ParseException */ public function parse(Token $token) { $value = $this->tokenizer->detokenize($token->getValue()); $realValue = preg_replace('/^<\\((.*)\\)>$/', '<identity($1)>', $value); return $this->decoratedTokenParser->parse(new Token($realValue, new TokenType(TokenType::FUNCTION_TYPE))); }
/** * @inheritdoc */ public function parse(Token $token) { return $token->getValue(); }
public static function createForUnparsableToken(Token $token, int $code = 0, \Throwable $previous = null) : ParseException { return new ParseException(sprintf('Could not parse the token "%s" (type: %s).', $token->getValue(), $token->getType()), $code, $previous); }