/** * @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'); }
/** * @return int */ public function tab() { $title = $this->response->getStatusCode(); $class = $this->response->getStatusCode() >= 400 ? 'danger' : 'success'; return ['title' => $title, 'class' => sprintf('response-code %s', $class)]; }
public function testResponseToString() { $this->response->getBody()->write('foo'); $this->assertEquals('foo', (string) $this->response); }
/** * Basic greeting example with parameters * * @param $name * @return Response */ public function helloAction($name) { return Response::create(sprintf('<body>Hello, %s!</body>', $name)); }