Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Lexer\GlobalPatternsLexer::lex PHP Method

lex() public method

public lex ( string $value ) : array
$value string
return array
    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))];
            }
        }
        return $this->lexer->lex($value);
    }

Usage Example

 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Invalid token "foo 10x @users" found.
  */
 public function testThrowsAnExceptionWhenInvalidValue()
 {
     $lexer = new GlobalPatternsLexer(new FakeLexer());
     $lexer->lex('foo 10x @users');
 }
GlobalPatternsLexer