예제 #1
0
 /**
  * Invoke the application.
  *
  * - Convert the PSR request/response into CakePHP equivalents.
  * - Create the controller that will handle this request.
  * - Invoke the controller.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request The request
  * @param \Psr\Http\Message\ResponseInterface $response The response
  * @param callable $next The next middleware
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     // Convert the request/response to CakePHP equivalents.
     $cakeRequest = RequestTransformer::toCake($request);
     $cakeResponse = ResponseTransformer::toCake($response);
     // Dispatch the request/response to CakePHP
     $cakeResponse = $this->getDispatcher()->dispatch($cakeRequest, $cakeResponse);
     // Convert the response back into a PSR7 object.
     return ResponseTransformer::toPsr($cakeResponse);
 }
예제 #2
0
 /**
  * {@inheritDoc}
  *
  * Will render the view and use the content as the body of the response.
  * It will also set the specified HTTP code and optional additional headers.
  */
 public function process(ServerRequestInterface $request, ResponseInterface $response)
 {
     $className = $this->_config['view']['className'];
     if (empty($className)) {
         $className = 'App\\View\\AppView';
     }
     $viewConfig = $this->_config['view'] ?: [];
     $view = new $className(RequestTransformer::toCake($request), ResponseTransformer::toCake($response), null, $viewConfig);
     $stream = new Stream(fopen('php://memory', 'r+'));
     $stream->write($view->render());
     $response = $response->withBody($stream);
     $response = $response->withStatus($this->_config['code']);
     $response = $this->addHeaders($response);
     return $response;
 }