Drupal investigation

NumberHandler.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\CssSelector\Parser\Handler;
  11. use Symfony\Component\CssSelector\Parser\Reader;
  12. use Symfony\Component\CssSelector\Parser\Token;
  13. use Symfony\Component\CssSelector\Parser\TokenStream;
  14. use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns;
  15. /**
  16. * CSS selector comment handler.
  17. *
  18. * This component is a port of the Python cssselect library,
  19. * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
  20. *
  21. * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
  22. *
  23. * @internal
  24. */
  25. class NumberHandler implements HandlerInterface
  26. {
  27. /**
  28. * @var TokenizerPatterns
  29. */
  30. private $patterns;
  31. /**
  32. * @param TokenizerPatterns $patterns
  33. */
  34. public function __construct(TokenizerPatterns $patterns)
  35. {
  36. $this->patterns = $patterns;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function handle(Reader $reader, TokenStream $stream)
  42. {
  43. $match = $reader->findPattern($this->patterns->getNumberPattern());
  44. if (!$match) {
  45. return false;
  46. }
  47. $stream->push(new Token(Token::TYPE_NUMBER, $match[0], $reader->getPosition()));
  48. $reader->moveForward(strlen($match[0]));
  49. return true;
  50. }
  51. }