You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.5 KiB

8 years ago
  1. <?hh // decl
  2. namespace FastRoute {
  3. class BadRouteException extends \LogicException {
  4. }
  5. interface RouteParser {
  6. public function parse(string $route): array<array>;
  7. }
  8. class RouteCollector {
  9. public function __construct(RouteParser $routeParser, DataGenerator $dataGenerator);
  10. public function addRoute(mixed $httpMethod, string $route, mixed $handler): void;
  11. public function getData(): array;
  12. }
  13. class Route {
  14. public function __construct(string $httpMethod, mixed $handler, string $regex, array $variables);
  15. public function matches(string $str): bool;
  16. }
  17. interface DataGenerator {
  18. public function addRoute(string $httpMethod, array $routeData, mixed $handler);
  19. public function getData(): array;
  20. }
  21. interface Dispatcher {
  22. const int NOT_FOUND = 0;
  23. const int FOUND = 1;
  24. const int METHOD_NOT_ALLOWED = 2;
  25. public function dispatch(string $httpMethod, string $uri): array;
  26. }
  27. function simpleDispatcher(
  28. (function(RouteCollector): void) $routeDefinitionCallback,
  29. shape(
  30. 'routeParser' => ?classname<RouteParser>,
  31. 'dataGenerator' => ?classname<DataGenerator>,
  32. 'dispatcher' => ?classname<Dispatcher>,
  33. 'routeCollector' => ?classname<RouteCollector>,
  34. ) $options = shape()): Dispatcher;
  35. function cachedDispatcher(
  36. (function(RouteCollector): void) $routeDefinitionCallback,
  37. shape(
  38. 'routeParser' => ?classname<RouteParser>,
  39. 'dataGenerator' => ?classname<DataGenerator>,
  40. 'dispatcher' => ?classname<Dispatcher>,
  41. 'routeCollector' => ?classname<RouteCollector>,
  42. 'cacheDisabled' => ?bool,
  43. 'cacheFile' => ?string,
  44. ) $options = shape()): Dispatcher;
  45. }
  46. namespace FastRoute\DataGenerator {
  47. abstract class RegexBasedAbstract implements \FastRoute\DataGenerator {
  48. protected abstract function getApproxChunkSize();
  49. protected abstract function processChunk($regexToRoutesMap);
  50. public function addRoute(string $httpMethod, array $routeData, mixed $handler): void;
  51. public function getData(): array;
  52. }
  53. class CharCountBased extends RegexBasedAbstract {
  54. protected function getApproxChunkSize(): int;
  55. protected function processChunk(array<string, string> $regexToRoutesMap): array<string, mixed>;
  56. }
  57. class GroupCountBased extends RegexBasedAbstract {
  58. protected function getApproxChunkSize(): int;
  59. protected function processChunk(array<string, string> $regexToRoutesMap): array<string, mixed>;
  60. }
  61. class GroupPosBased extends RegexBasedAbstract {
  62. protected function getApproxChunkSize(): int;
  63. protected function processChunk(array<string, string> $regexToRoutesMap): array<string, mixed>;
  64. }
  65. class MarkBased extends RegexBasedAbstract {
  66. protected function getApproxChunkSize(): int;
  67. protected function processChunk(array<string, string> $regexToRoutesMap): array<string, mixed>;
  68. }
  69. }
  70. namespace FastRoute\Dispatcher {
  71. abstract class RegexBasedAbstract implements \FastRoute\Dispatcher {
  72. protected abstract function dispatchVariableRoute(array<array> $routeData, string $uri): array;
  73. public function dispatch(string $httpMethod, string $uri): array;
  74. }
  75. class GroupPosBased extends RegexBasedAbstract {
  76. public function __construct(array $data);
  77. protected function dispatchVariableRoute(array<array> $routeData, string $uri): array;
  78. }
  79. class GroupCountBased extends RegexBasedAbstract {
  80. public function __construct(array $data);
  81. protected function dispatchVariableRoute(array<array> $routeData, string $uri): array;
  82. }
  83. class CharCountBased extends RegexBasedAbstract {
  84. public function __construct(array $data);
  85. protected function dispatchVariableRoute(array<array> $routeData, string $uri): array;
  86. }
  87. class MarkBased extends RegexBasedAbstract {
  88. public function __construct(array $data);
  89. protected function dispatchVariableRoute(array<array> $routeData, string $uri): array;
  90. }
  91. }
  92. namespace FastRoute\RouteParser {
  93. class Std implements \FastRoute\RouteParser {
  94. const string VARIABLE_REGEX = <<<'REGEX'
  95. \{
  96. \s* ([a-zA-Z][a-zA-Z0-9_]*) \s*
  97. (?:
  98. : \s* ([^{}]*(?:\{(?-1)\}[^{}]*)*)
  99. )?
  100. \}
  101. REGEX;
  102. const string DEFAULT_DISPATCH_REGEX = '[^/]+';
  103. public function parse(string $route): array<array>;
  104. }
  105. }