SyntaxErrorException.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /**
  23. * @return self
  24. */
  25. public static function unexpectedToken(string $expectedValue, Token $foundToken)
  26. {
  27. return new self(sprintf('Expected %s, but %s found.', $expectedValue, $foundToken));
  28. }
  29. /**
  30. * @return self
  31. */
  32. public static function pseudoElementFound(string $pseudoElement, string $unexpectedLocation)
  33. {
  34. return new self(sprintf('Unexpected pseudo-element "::%s" found %s.', $pseudoElement, $unexpectedLocation));
  35. }
  36. /**
  37. * @return self
  38. */
  39. public static function unclosedString(int $position)
  40. {
  41. return new self(sprintf('Unclosed/invalid string at %s.', $position));
  42. }
  43. /**
  44. * @return self
  45. */
  46. public static function nestedNot()
  47. {
  48. return new self('Got nested ::not().');
  49. }
  50. /**
  51. * @return self
  52. */
  53. public static function stringAsFunctionArgument()
  54. {
  55. return new self('String not allowed as function argument.');
  56. }
  57. }