Commit 8264be8e authored by Fabien Potencier's avatar Fabien Potencier

prevented the execution of the before middlewares when an app before filter...

prevented the execution of the before middlewares when an app before filter returns a Response (refs #452)
parent a9e34f08
......@@ -550,6 +550,10 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->beforeDispatched = true;
$this['dispatcher']->dispatch(SilexEvents::BEFORE, $event);
if ($event->hasResponse()) {
return;
}
}
$this['route_before_middlewares_trigger']($event);
......
......@@ -163,6 +163,21 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(2, $i);
}
public function testBeforeFilterPreventsBeforeMiddlewaresToBeExecuted()
{
$app = new Application();
$app->before(function () { return new Response('app before'); });
$app->get('/', function() {
return new Response('test');
})->before(function() {
return new Response('middleware before');
});
$this->assertEquals('app before', $app->handle(Request::create('/'))->getContent());
}
public function testBeforeFilterExceptionsWhenHandlingAnException()
{
$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