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