Commit a0644877 authored by Romain Neutron's avatar Romain Neutron Committed by Fabien Potencier

Convert request attributes in the KernelEvents::REQUEST event instead of...

Convert request attributes in the KernelEvents::REQUEST event instead of KernelEvents::CONTROLLER event (closes #825)
parent 3b207399
......@@ -13,7 +13,7 @@ namespace Silex\EventListener;
use Silex\CallbackResolver;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouteCollection;
......@@ -42,9 +42,9 @@ class ConverterListener implements EventSubscriberInterface
/**
* Handles converters.
*
* @param FilterControllerEvent $event The event to handle
* @param GetResponseEvent $event The event to handle
*/
public function onKernelController(FilterControllerEvent $event)
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$route = $this->routes->get($request->attributes->get('_route'));
......@@ -60,7 +60,7 @@ class ConverterListener implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
KernelEvents::CONTROLLER => 'onKernelController',
KernelEvents::REQUEST => 'onKernelRequest',
);
}
}
......@@ -122,6 +122,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foobar', $response->getContent());
}
public function testConvertedAttributeIsAvailableInBeforeFilter()
{
$app = new Application();
$beforeValue = null;
$app
->get('/foo/{foo}', function ($foo) {
return $foo;
})
->convert('foo', function ($foo) { return $foo.'converted'; })
->before(function (Request $request) use (&$beforeValue) {
$beforeValue = $request->attributes->get('foo');
});
$response = $app->handle(Request::create('/foo/bar'));
$this->assertEquals('barconverted', $beforeValue);
$this->assertEquals('barconverted', $response->getContent());
}
public function testOn()
{
$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