public function route(Request $request = null) { $response = null; try { if ($request === null) { $request = Request::generate(); } $request->method = strtolower($request->method); if (!array_key_exists($request->method, $this->handlers) || $this->handlers[$request->method] === null) { throw new MethodNotAllowedException(); } $handler = $this->handlers[$request->method]; $response = $handler($request, $this->services); } catch (HTTPException $e) { $response = $e; } catch (Exception $e) { throw $e; $response = new InternalServerException(null, null, $e); } $response = $this->normalizeResponse($response); http_response_code($response->code); foreach ($response->headers as $key => $value) { header($key . ':' . $value); } echo $this->encodeResponse($response); }
<?php require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../src/Request.php'; require_once __DIR__ . '/../src/Map.php'; $request = Request::generate(); echo json_encode($request); $map = new Map(['foo' => 'bar']);