Exemplo n.º 1
0
 /**
  * @param ServerRequestInterface $request
  * @return Response|mixed
  */
 public function handle(ServerRequestInterface $request)
 {
     try {
         $route = $this->router->resolve($request);
         $response = $this->resolve($route->getAction(), $route->getQueryParams());
         if (false === $response instanceof ResponseInterface) {
             $response = Response::create($response);
         }
     } catch (NotFoundException $e) {
         $response = Response::create('<body>Not Found</body>', 404);
     } catch (\Exception $e) {
         $response = Response::create(sprintf('<body>An unkown error has occurred: %s</body>', $e->getMessage()), 500);
     }
     $this->registry->add('response', $response);
     return $this->registry->make('response');
 }
Exemplo n.º 2
0
 /**
  * Registers error handler with container
  * And converts all errors into ErrorExceptions
  *
  * @return void
  */
 protected function errorHandling()
 {
     $handler = new ErrorHandler();
     $this->container->add('error', $handler);
 }