Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove subrequest feature. Fixes #2044. #2078

Merged
merged 1 commit into from
Nov 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions Slim/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
45 changes: 0 additions & 45 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down