EmptyStringParser.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\Shortcut;
  11. use Symfony\Component\CssSelector\Node\ElementNode;
  12. use Symfony\Component\CssSelector\Node\SelectorNode;
  13. use Symfony\Component\CssSelector\Parser\ParserInterface;
  14. /**
  15. * CSS selector class parser shortcut.
  16. *
  17. * This shortcut ensure compatibility with previous version.
  18. * - The parser fails to parse an empty string.
  19. * - In the previous version, an empty string matches each tags.
  20. *
  21. * This component is a port of the Python cssselect library,
  22. * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
  23. *
  24. * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
  25. *
  26. * @internal
  27. */
  28. class EmptyStringParser implements ParserInterface
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function parse(string $source): array
  34. {
  35. // Matches an empty string
  36. if ('' == $source) {
  37. return [new SelectorNode(new ElementNode(null, '*'))];
  38. }
  39. return [];
  40. }
  41. }