Symfony\Component\CssSelector\Parser::parse PHP Method

parse() public method

public parse ( $string )
    public function parse($string)
    {
        $tokenizer = new Tokenizer();
        $stream = new TokenStream($tokenizer->tokenize($string), $string);
        try {
            return $this->parseSelectorGroup($stream);
        } catch (\Exception $e) {
            $class = get_class($e);
            throw new $class(sprintf('%s at %s -> %s', $e->getMessage(), implode($stream->getUsed(), ''), $stream->peek()), 0, $e);
        }
    }

Usage Example

Beispiel #1
0
 public function testParseExceptions()
 {
     $parser = new Parser();
     try {
         $parser->parse('h1:');
         $this->fail('->parse() throws an Exception if the css selector is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Symfony\\Component\\CssSelector\\SyntaxError', $e, '->parse() throws an Exception if the css selector is not valid');
         $this->assertEquals("Expected symbol, got '' at h1: -> ", $e->getMessage(), '->parse() throws an Exception if the css selector is not valid');
     }
 }