JsonResponse.php
9 years ago
Request.php
3 weeks ago
Response.php
3 weeks ago
Router.php
8 years ago
Router.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\Http; |
| 4 | |
| 5 | |
| 6 | class Router |
| 7 | { |
| 8 | public function route($route, $secure = true) |
| 9 | { |
| 10 | $container = new \Wpae\Di\WpaeDi(array()); |
| 11 | |
| 12 | $request = new Request(file_get_contents('php://input')); |
| 13 | |
| 14 | $q = $route; |
| 15 | $routeParts = explode('/', $q); |
| 16 | if($secure){ |
| 17 | $controller = 'Wpae\\App\\Controller\\'.ucwords($routeParts[0]).'Controller'; |
| 18 | } else { |
| 19 | $controller = 'Wpae\\App\\UnsecuredController\\'.ucwords($routeParts[0]).'Controller'; |
| 20 | } |
| 21 | $action = ucwords($routeParts[1]).'Action'; |
| 22 | |
| 23 | $controller = new $controller($container); |
| 24 | $response = $controller->$action($request); |
| 25 | |
| 26 | if(!$response instanceof \Wpae\Http\Response) { |
| 27 | throw new \Exception('The controller must return an HttpResponse instance.'); |
| 28 | } |
| 29 | |
| 30 | $response->render(); |
| 31 | } |
| 32 | } |