diff --git a/Slim/App.php b/Slim/App.php index 3b31a12ec..5dfd2920e 100644 --- a/Slim/App.php +++ b/Slim/App.php @@ -14,6 +14,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; use Slim\Exception\MethodNotAllowedException; use Slim\Exception\NotFoundException; use Slim\Handlers\Error; @@ -37,7 +38,7 @@ * configure, and run a Slim Framework application. * The \Slim\App class also accepts Slim Framework middleware. */ -class App +class App implements RequestHandlerInterface { use MiddlewareAwareTrait; @@ -558,15 +559,30 @@ public function run() // create request $request = Request::createFromGlobals($_SERVER); + $response = $this->handle($request); + + $this->respond($response); + return $response; + } + + /** + * Handle a request + * + * This method traverses the application middleware stack and then returns the + * resultant Response object. + * + * @param ServerRequestInterface $request + * @param ResponseInterface $response + * @return ResponseInterface + */ + public function handle(ServerRequestInterface $request): ResponseInterface + { // create response $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']); $response = new Response(200, $headers); $response = $response->withProtocolVersion($this->getSetting('httpVersion')); - $response = $this->process($request, $response); - - $this->respond($response); - return $response; + return $this->process($request, $response); } /**