Zend\Expressive\Application::run PHP Method

run() public method

If no request or response are provided, the method will use ServerRequestFactory::fromGlobals to create a request instance, and instantiate a default response instance. It then will invoke itself with the request and response, and emit the returned response using the composed emitter.
public run ( Psr\Http\Message\ServerRequestInterface $request = null, Psr\Http\Message\ResponseInterface $response = null )
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
    public function run(ServerRequestInterface $request = null, ResponseInterface $response = null)
    {
        $response = $response ?: new Response();
        $request = $request ?: ServerRequestFactory::fromGlobals();
        $request = $request->withAttribute('originalResponse', $response);
        $response = $this($request, $response);
        $emitter = $this->getEmitter();
        $emitter->emit($response);
    }

Usage Example

 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $inputStream = fopen('php://memory', 'r+');
     $content = $request->getContent();
     if ($content !== null) {
         fwrite($inputStream, $content);
         rewind($inputStream);
     }
     $queryParams = [];
     $postParams = [];
     $queryString = parse_url($request->getUri(), PHP_URL_QUERY);
     if ($queryString != '') {
         parse_str($queryString, $queryParams);
     }
     if ($request->getMethod() !== 'GET') {
         $postParams = $request->getParameters();
     }
     $serverParams = $request->getServer();
     if (!isset($serverParams['SCRIPT_NAME'])) {
         //required by WhoopsErrorHandler
         $serverParams['SCRIPT_NAME'] = 'Codeception';
     }
     $zendRequest = new ServerRequest($serverParams, $this->convertFiles($request->getFiles()), $request->getUri(), $request->getMethod(), $inputStream, $this->extractHeaders($request));
     $zendRequest = $zendRequest->withCookieParams($request->getCookies())->withQueryParams($queryParams)->withParsedBody($postParams);
     $cwd = getcwd();
     chdir(codecept_root_dir());
     $this->application->run($zendRequest);
     chdir($cwd);
     $this->request = $zendRequest;
     $response = $this->responseCollector->getResponse();
     $this->responseCollector->clearResponse();
     return new Response($response->getBody(), $response->getStatusCode(), $response->getHeaders());
 }
All Usage Examples Of Zend\Expressive\Application::run