1 | <?php |
||
10 | class Router extends EventEmitter |
||
11 | { |
||
12 | use WaterfallTrait; |
||
13 | /** |
||
14 | * The current routes list |
||
15 | * @var array |
||
16 | */ |
||
17 | public $routes = []; |
||
18 | |||
19 | /** |
||
20 | * The current asked uri |
||
21 | * @var string|boolean |
||
22 | */ |
||
23 | private $uri = false; |
||
24 | |||
25 | /** |
||
26 | * Create a new routing element |
||
27 | * |
||
28 | * @param array $routes a route array |
||
29 | * |
||
30 | * @throws \InvalidArgumentException |
||
31 | */ |
||
32 | public function __construct($routes = []) |
||
40 | |||
41 | /** |
||
42 | * Add routes |
||
43 | * |
||
44 | * @param array $routes a route array |
||
45 | * |
||
46 | * @throws \InvalidArgumentException |
||
47 | * @return Void |
||
48 | */ |
||
49 | public function addRoutes($routes) |
||
61 | |||
62 | /** |
||
63 | * Add a new route |
||
64 | * |
||
65 | * @param String $method type of route |
||
66 | * @param String $route uri to catch |
||
67 | * @param Callable $callback |
||
68 | */ |
||
69 | public function addRoute($method, $route, $callback) |
||
73 | |||
74 | /** |
||
75 | * Create a new group of routes |
||
76 | * |
||
77 | * @param String $prefix prefix of thes routes |
||
78 | * |
||
79 | * @return \CapMousse\ReactRestify\Routing\Group |
||
80 | */ |
||
81 | public function addGroup($prefix, $callback) |
||
87 | |||
88 | /** |
||
89 | * Launch the route parsing |
||
90 | * |
||
91 | * @param \React\Http\Request $request |
||
92 | * @param \React\Restify\Response $response |
||
93 | * |
||
94 | * @throws \RuntimeException |
||
95 | * @return Void |
||
96 | */ |
||
97 | public function launch(Request $request, Response $response) |
||
119 | |||
120 | /** |
||
121 | * Try to match the current uri with all routes |
||
122 | * |
||
123 | * |
||
124 | * @param \React\Http\Request $request |
||
125 | * @param \React\Restify\Response $response |
||
126 | * |
||
127 | * @throws \RuntimeException |
||
128 | * @return Void |
||
129 | */ |
||
130 | private function matchRoutes(Request $request, Response $response) |
||
173 | } |
||
174 |