Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\CssSelector\Parser\Handler; Chris@0: Chris@0: use Symfony\Component\CssSelector\Parser\Reader; Chris@0: use Symfony\Component\CssSelector\Parser\Token; Chris@0: use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping; Chris@0: use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns; Chris@17: use Symfony\Component\CssSelector\Parser\TokenStream; Chris@0: Chris@0: /** Chris@0: * CSS selector comment handler. Chris@0: * Chris@0: * This component is a port of the Python cssselect library, Chris@0: * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. Chris@0: * Chris@0: * @author Jean-François Simon Chris@0: * Chris@0: * @internal Chris@0: */ Chris@0: class IdentifierHandler implements HandlerInterface Chris@0: { Chris@0: private $patterns; Chris@0: private $escaping; Chris@0: Chris@0: public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping) Chris@0: { Chris@0: $this->patterns = $patterns; Chris@0: $this->escaping = $escaping; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function handle(Reader $reader, TokenStream $stream) Chris@0: { Chris@0: $match = $reader->findPattern($this->patterns->getIdentifierPattern()); Chris@0: Chris@0: if (!$match) { Chris@0: return false; Chris@0: } Chris@0: Chris@0: $value = $this->escaping->escapeUnicode($match[0]); Chris@0: $stream->push(new Token(Token::TYPE_IDENTIFIER, $value, $reader->getPosition())); Chris@17: $reader->moveForward(\strlen($match[0])); Chris@0: Chris@0: return true; Chris@0: } Chris@0: }