Commit d2b59062 authored by Nils Adermann's avatar Nils Adermann

Allow global after middlewares to return responses like route specific ones

parent f64ac7b8
...@@ -339,7 +339,12 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -339,7 +339,12 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
return; return;
} }
call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app); $response = call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app);
if ($response instanceof Response) {
$event->setResponse($response);
} elseif (null !== $response) {
throw new \RuntimeException('An after middleware returned an invalid response value. Must return null or an instance of Response.');
}
}, $priority); }, $priority);
} }
......
...@@ -234,6 +234,20 @@ class MiddlewareTest extends \PHPUnit_Framework_TestCase ...@@ -234,6 +234,20 @@ class MiddlewareTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo---', $app->handle($request)->getContent()); $this->assertEquals('foo---', $app->handle($request)->getContent());
} }
public function testAfterFilterCanReturnResponse()
{
$app = new Application();
$app->after(function (Request $request, Response $response) {
return new Response('bar');
});
$app->match('/', function () { return new Response('foo'); });
$request = Request::create('/');
$this->assertEquals('bar', $app->handle($request)->getContent());
}
public function testRouteAndApplicationMiddlewareParameterInjection() public function testRouteAndApplicationMiddlewareParameterInjection()
{ {
$app = new Application(); $app = new Application();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment