fork download
  1. <?php
  2. \\FastRoute\RouteParser\Std;
  3.  
  4. class Std implements RouteParser
  5. {
  6. const VARIABLE_REGEX = <<<'REGEX'
  7. \{
  8.   \s* ([a-zA-Z_][a-zA-Z0-9_-]*) \s*
  9.   (?:
  10.   : \s* ([^{}]*(?:\{(?-1)\}[^{}]*)*)
  11.   )?
  12. \}
  13. REGEX;
  14. const DEFAULT_DISPATCH_REGEX = '[^/]+';
  15.  
  16. public function parse($route)
  17. {
  18. $routeWithoutClosingOptionals = rtrim($route, ']');
  19.  
  20. $numOptionals = strlen($route) - strlen($routeWithoutClosingOptionals);
  21.  
  22. // Split on [ while skipping placeholders
  23. $segments = preg_split('~' . self::VARIABLE_REGEX . '(*SKIP)(*F) | \[~x', $routeWithoutClosingOptionals);
  24.  
  25. if ($numOptionals !== count($segments) - 1) {
  26. // If there are any ] in the middle of the route, throw a more specific error message
  27. if (preg_match('~' . self::VARIABLE_REGEX . '(*SKIP)(*F) | \]~x', $routeWithoutClosingOptionals)) {
  28. throw new BadRouteException('Optional segments can only occur at the end of a route');
  29. }
  30. throw new BadRouteException("Number of opening '[' and closing ']' does not match");
  31. }
  32.  
  33. $currentRoute = '';
  34. $routeDatas = [];
  35. foreach ($segments as $n => $segment) {
  36.  
  37. if ($segment === '' && $n !== 0) {
  38. throw new BadRouteException('Empty optional part');
  39. }
  40.  
  41. $currentRoute .= $segment;
  42. $routeDatas[] = $this->parsePlaceholders($currentRoute);
  43.  
  44. }
  45.  
  46. return $routeDatas;
  47. }
  48. }
Runtime error #stdin #stdout #stderr 0.03s 24148KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Parse error:  syntax error, unexpected '\' (T_NS_SEPARATOR), expecting identifier (T_STRING) in /home/qVwHL6/prog.php on line 2