Skip to content

Commit

Permalink
Merge pull request laravel#817 from jgrossi/fix-issue-667
Browse files Browse the repository at this point in the history
Change Request instance for responses implementing Responsable interface
  • Loading branch information
taylorotwell authored Oct 3, 2018
2 parents f4dad7e + 7e6a9bf commit 2a85d2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Concerns/RoutesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ protected function sendThroughPipeline(array $middleware, Closure $then)
public function prepareResponse($response)
{
if ($response instanceof Responsable) {
$response = $response->toResponse(Request::capture());
$response = $response->toResponse(app(Request::class));
}

if ($response instanceof PsrResponseInterface) {
Expand Down
23 changes: 23 additions & 0 deletions tests/FullApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ public function testMethodNotAllowedResponse()
$this->assertEquals(405, $response->getStatusCode());
}

public function testResponsableInterface()
{
$app = new Application;

$app->router->get('/foo/{foo}', function () {
return new ResponsableResponse;
});

$request = Request::create('/foo/999', 'GET');
$response = $app->handle($request);

$this->assertEquals(999, $request->route('foo'));
$this->assertEquals(999, $response->original);
}

public function testUncaughtExceptionResponse()
{
$app = new Application;
Expand Down Expand Up @@ -771,3 +786,11 @@ public function terminate($request, Illuminate\Http\Response $response)
$response->setContent('TERMINATED');
}
}

class ResponsableResponse implements \Illuminate\Contracts\Support\Responsable
{
public function toResponse($request)
{
return $request->route('foo');
}
}

0 comments on commit 2a85d2b

Please sign in to comment.