예제 #1
0
파일: Kernel.php 프로젝트: fyuze/framework
 /**
  * @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
 /**
  * @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)];
 }
예제 #3
0
 public function testResponseToString()
 {
     $this->response->getBody()->write('foo');
     $this->assertEquals('foo', (string) $this->response);
 }
예제 #4
0
 /**
  * Basic greeting example with parameters
  *
  * @param $name
  * @return Response
  */
 public function helloAction($name)
 {
     return Response::create(sprintf('<body>Hello, %s!</body>', $name));
 }