1 | <?php |
||
11 | class Router extends EventEmitter |
||
12 | { |
||
13 | use WaterfallTrait; |
||
14 | /** |
||
15 | * The current routes list |
||
16 | * @var array |
||
17 | */ |
||
18 | public $routes = []; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | private $middlewares = []; |
||
24 | |||
25 | /** |
||
26 | * The current asked uri |
||
27 | * @var string|boolean |
||
28 | */ |
||
29 | private $uri = false; |
||
30 | |||
31 | /** |
||
32 | * Create a new routing element |
||
33 | * |
||
34 | * @param array $routes a route array |
||
35 | * |
||
36 | * @throws \InvalidArgumentException |
||
37 | */ |
||
38 | public function __construct($routes = []) |
||
46 | |||
47 | /** |
||
48 | * Add routes |
||
49 | * |
||
50 | * @param array $routes a route array |
||
51 | * |
||
52 | * @throws \InvalidArgumentException |
||
53 | * @return Void |
||
54 | */ |
||
55 | public function addRoutes($routes) |
||
67 | |||
68 | /** |
||
69 | * Add a new route |
||
70 | * |
||
71 | * @param String $method type of route |
||
72 | * @param String $route uri to catch |
||
73 | * @param Callable $callback |
||
74 | */ |
||
75 | public function addRoute($method, $route, $callback) |
||
79 | |||
80 | /** |
||
81 | * Create a new group of routes |
||
82 | * |
||
83 | * @param String $prefix prefix of thes routes |
||
84 | * |
||
85 | * @return \CapMousse\ReactRestify\Routing\Group |
||
86 | */ |
||
87 | public function addGroup($prefix, $callback) |
||
93 | |||
94 | /** |
||
95 | * Add a middleware |
||
96 | * @param string|Callable $callback |
||
97 | */ |
||
98 | public function addMiddleware($callback) |
||
111 | |||
112 | /** |
||
113 | * Launch the route parsing |
||
114 | * |
||
115 | * @param \React\Http\Request $request |
||
116 | * @param \React\Restify\Response $response |
||
117 | * |
||
118 | * @throws \RuntimeException |
||
119 | * @return Void |
||
120 | */ |
||
121 | public function launch(Request $request, Response $response) |
||
143 | |||
144 | /** |
||
145 | * Try to match the current uri with all routes |
||
146 | * |
||
147 | * |
||
148 | * @param \React\Http\Request $request |
||
149 | * @param \React\Restify\Response $response |
||
150 | * |
||
151 | * @throws \RuntimeException |
||
152 | * @return Void |
||
153 | */ |
||
154 | private function matchRoutes(Request $request, Response $response) |
||
184 | |||
185 | /** |
||
186 | * Launch route stack |
||
187 | * @param array $stack |
||
188 | * @param Request $request |
||
189 | * @param Response $response |
||
190 | * @return void |
||
191 | */ |
||
192 | protected function runStack(array $stack, Request $request, Response $response) |
||
201 | } |
||
202 |