/** * @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'); }
public function testStaticCreationMethod() { $response = \Fyuze\Http\Response::create('foobar'); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('foobar', (string) $response->getBody()); }
/** * Basic greeting example with parameters * * @param $name * @return Response */ public function helloAction($name) { return Response::create(sprintf('<body>Hello, %s!</body>', $name)); }