createForCouldNotLexValue() public static méthode

public static createForCouldNotLexValue ( string $value ) : LexException
$value string
Résultat LexException
 public function testTestCreateForCouldNotLexValue()
 {
     $exception = ExpressionLanguageExceptionFactory::createForCouldNotLexValue('foo');
     $this->assertEquals('Could not lex the value "foo".', $exception->getMessage());
     $this->assertEquals(0, $exception->getCode());
     $this->assertNull($exception->getPrevious());
 }
Exemple #2
0
 /**
  * Lex a value with the mask "@X" where X is a valid possible reference
  *
  * {@inheritdoc}
  *
  * @throws LexException
  */
 public function lex(string $value) : array
 {
     foreach (self::PATTERNS as $pattern => $tokenTypeConstant) {
         if (1 === preg_match($pattern, $value, $matches)) {
             if (null === $tokenTypeConstant) {
                 throw InvalidArgumentExceptionFactory::createForInvalidExpressionLanguageToken($value);
             }
             return [new Token($matches[0], new TokenType($tokenTypeConstant))];
         }
     }
     throw ExpressionLanguageExceptionFactory::createForCouldNotLexValue($value);
 }
Exemple #3
0
 /**
  * @param LexerInterface $referenceLexer
  * @param string         $valueFragment
  *
  * @throws LexException
  *
  * @return Token[]
  */
 private function lexFragment(LexerInterface $referenceLexer, string $valueFragment) : array
 {
     foreach (self::PATTERNS as $pattern => $tokenTypeConstant) {
         if (1 === preg_match($pattern, $valueFragment, $matches)) {
             if (null === $tokenTypeConstant) {
                 throw InvalidArgumentExceptionFactory::createForInvalidExpressionLanguageToken($valueFragment);
             }
             $match = $matches[1];
             if (self::REFERENCE_LEXER === $tokenTypeConstant) {
                 return $referenceLexer->lex($match);
             }
             return [new Token($match, new TokenType($tokenTypeConstant))];
         }
     }
     throw ExpressionLanguageExceptionFactory::createForCouldNotLexValue($valueFragment);
 }
 /**
  * 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);
 }