From 7b01ca478f9f4536a60fe7e8670e2ddb1dbeb609 Mon Sep 17 00:00:00 2001 From: Andrew Carter Date: Fri, 18 Dec 2015 10:05:51 +0000 Subject: [PATCH 1/2] Added App::process() to expose Request -> Response functionality --- Slim/App.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Slim/App.php b/Slim/App.php index 641270cbc..8cdc8f06b 100644 --- a/Slim/App.php +++ b/Slim/App.php @@ -297,13 +297,39 @@ public function run($silent = false) $request = $this->container->get('request'); $response = $this->container->get('response'); + $response = $this->process($request, $response); + + $response = $this->finalize($response); + + if (!$silent) { + $this->respond($response); + } + + return $response; + } + + /** + * Process a request + * + * This method traverses the application middleware stack and then returns the + * resultant Response object. + * + * @param ServerRequestInterface $request + * @param ResponseInterface $response + * @return ResponseInterface + * + * @throws Exception + * @throws MethodNotAllowedException + * @throws NotFoundException + */ + public function process(ServerRequestInterface $request, ResponseInterface $response) + { // Ensure basePath is set $router = $this->container->get('router'); if (is_callable([$request->getUri(), 'getBasePath']) && is_callable([$router, 'setBasePath'])) { $router->setBasePath($request->getUri()->getBasePath()); } - // Dispatch the Router first if the setting for this is on if ($this->container->get('settings')['determineRouteBeforeAppMiddleware'] === true) { // Dispatch router (note: you won't be able to alter routes after this) @@ -338,12 +364,6 @@ public function run($silent = false) $response = $errorHandler($request, $response, $e); } - $response = $this->finalize($response); - - if (!$silent) { - $this->respond($response); - } - return $response; } From 8bc17f1ef66b8b0ec8edde653b763357c6403745 Mon Sep 17 00:00:00 2001 From: Andrew Carter Date: Fri, 18 Dec 2015 13:58:55 +0000 Subject: [PATCH 2/2] Moved `App::finalize($response)` call into `App::process()` --- Slim/App.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Slim/App.php b/Slim/App.php index 8cdc8f06b..1c7422fc8 100644 --- a/Slim/App.php +++ b/Slim/App.php @@ -299,8 +299,6 @@ public function run($silent = false) $response = $this->process($request, $response); - $response = $this->finalize($response); - if (!$silent) { $this->respond($response); } @@ -364,6 +362,8 @@ public function process(ServerRequestInterface $request, ResponseInterface $resp $response = $errorHandler($request, $response, $e); } + $response = $this->finalize($response); + return $response; }