From 263ce352ed32df7931f903ed6eeba73949891e74 Mon Sep 17 00:00:00 2001 From: Josh Lockhart Date: Sat, 26 Nov 2016 12:18:32 -0500 Subject: [PATCH] Remove subrequest feature. Fixes #2044. --- Slim/App.php | 43 ------------------------------------------- tests/AppTest.php | 45 --------------------------------------------- 2 files changed, 88 deletions(-) diff --git a/Slim/App.php b/Slim/App.php index 747e8e3af..e17099dd9 100644 --- a/Slim/App.php +++ b/Slim/App.php @@ -453,49 +453,6 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res return $notFoundHandler($request, $response); } - /** - * Perform a sub-request from within an application route - * - * This method allows you to prepare and initiate a sub-request, run within - * the context of the current request. This WILL NOT issue a remote HTTP - * request. Instead, it will route the provided URL, method, headers, - * cookies, body, and server variables against the set of registered - * application routes. The result response object is returned. - * - * @param string $method The request method (e.g., GET, POST, PUT, etc.) - * @param string $path The request URI path - * @param string $query The request URI query string - * @param array $headers The request headers (key-value array) - * @param array $cookies The request cookies (key-value array) - * @param string $bodyContent The request body - * @param ResponseInterface $response The response object (optional) - * @return ResponseInterface - */ - public function subRequest( - $method, - $path, - $query = '', - array $headers = [], - array $cookies = [], - $bodyContent = '', - ResponseInterface $response = null - ) { - $env = $this->container->get('environment'); - $uri = Uri::createFromEnvironment($env)->withPath($path)->withQuery($query); - $headers = new Headers($headers); - $serverParams = $env->all(); - $body = new Body(fopen('php://temp', 'r+')); - $body->write($bodyContent); - $body->rewind(); - $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body); - - if (!$response) { - $response = $this->container->get('response'); - } - - return $this($request, $response); - } - /** * Dispatch the router to find the route. Prepare the route for use. * diff --git a/tests/AppTest.php b/tests/AppTest.php index 2ddb0fc88..99f840209 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -1404,51 +1404,6 @@ public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArgumentsRe $this->assertEquals('1rob', (string)$resOut->getBody()); } - public function testInvokeSubRequest() - { - $app = new App(); - $app->get('/foo', function ($req, $res) { - $res->write('foo'); - - return $res; - }); - - $newResponse = $subReq = $app->subRequest('GET', '/foo'); - - $this->assertEquals('foo', (string)$subReq->getBody()); - $this->assertEquals(200, $newResponse->getStatusCode()); - } - - public function testInvokeSubRequestWithQuery() - { - $app = new App(); - $app->get('/foo', function ($req, $res) { - $res->write("foo {$req->getParam('bar')}"); - - return $res; - }); - - $subReq = $app->subRequest('GET', '/foo', 'bar=bar'); - - $this->assertEquals('foo bar', (string)$subReq->getBody()); - } - - public function testInvokeSubRequestUsesResponseObject() - { - $app = new App(); - $app->get('/foo', function ($req, $res) { - $res->write("foo {$req->getParam('bar')}"); - - return $res; - }); - - $resp = new Response(201); - $newResponse = $subReq = $app->subRequest('GET', '/foo', 'bar=bar', [], [], '', $resp); - - $this->assertEquals('foo bar', (string)$subReq->getBody()); - $this->assertEquals(201, $newResponse->getStatusCode()); - } - // TODO: Test finalize() // TODO: Test run()