SyntaxErrorException.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Exception;
  11. use Symfony\Component\CssSelector\Parser\Token;
  12. /**
  13. * ParseException is thrown when a CSS selector syntax is not valid.
  14. *
  15. * This component is a port of the Python cssselect library,
  16. * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
  17. *
  18. * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
  19. */
  20. class SyntaxErrorException extends ParseException
  21. {
  22. public static function unexpectedToken(string $expectedValue, Token $foundToken): self
  23. {
  24. return new self(sprintf('Expected %s, but %s found.', $expectedValue, $foundToken));
  25. }
  26. public static function pseudoElementFound(string $pseudoElement, string $unexpectedLocation): self
  27. {
  28. return new self(sprintf('Unexpected pseudo-element "::%s" found %s.', $pseudoElement, $unexpectedLocation));
  29. }
  30. public static function unclosedString(int $position): self
  31. {
  32. return new self(sprintf('Unclosed/invalid string at %s.', $position));
  33. }
  34. public static function nestedNot(): self
  35. {
  36. return new self('Got nested ::not().');
  37. }
  38. public static function notAtTheStartOfASelector(string $pseudoElement): self
  39. {
  40. return new self(sprintf('Got immediate child pseudo-element ":%s" not at the start of a selector', $pseudoElement));
  41. }
  42. public static function stringAsFunctionArgument(): self
  43. {
  44. return new self('String not allowed as function argument.');
  45. }
  46. }