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