SyntaxErrorException.php 1.8 KB

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