From 4df8ff614cf7cf37c1668f6bba7c4a93ba08abdf Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Thu, 31 Aug 2017 14:04:25 +0200 Subject: [PATCH] Read "propel_converter" options from request attributes (#449) --- .../ParamConverter/PropelParamConverter.php | 17 ++--------- Resources/config/converters.xml | 4 --- .../PropelParamConverterTest.php | 28 ++++++------------- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/Request/ParamConverter/PropelParamConverter.php b/Request/ParamConverter/PropelParamConverter.php index 21fa85b..520f728 100644 --- a/Request/ParamConverter/PropelParamConverter.php +++ b/Request/ParamConverter/PropelParamConverter.php @@ -9,7 +9,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\RouterInterface; /** * PropelParamConverter @@ -60,16 +59,6 @@ class PropelParamConverter implements ParamConverterInterface */ protected $hasWith = false; - /** - * @var RouterInterface - */ - protected $router; - - public function setRouter(RouterInterface $router = null) - { - $this->router = $router; - } - /** * @param Request $request * @param ParamConverter $configuration @@ -102,9 +91,9 @@ class PropelParamConverter implements ParamConverterInterface $options = $configuration->getOptions(); - // Check route options for converter options, if there are non provided. - if (empty($options) && $request->attributes->has('_route') && $this->router && $configuration instanceof ParamConverter) { - $converterOption = $this->router->getRouteCollection()->get($request->attributes->get('_route'))->getOption('propel_converter'); + // Check request attributes for converter options, if there are non provided. + if (empty($options) && $request->attributes->has('propel_converter') && $configuration instanceof ParamConverter) { + $converterOption = $request->attributes->get('propel_converter'); if (!empty($converterOption[$configuration->getName()])) { $options = $converterOption[$configuration->getName()]; } diff --git a/Resources/config/converters.xml b/Resources/config/converters.xml index a79e295..086f35e 100644 --- a/Resources/config/converters.xml +++ b/Resources/config/converters.xml @@ -11,10 +11,6 @@ - - - - diff --git a/Tests/Request/ParamConverter/PropelParamConverterTest.php b/Tests/Request/ParamConverter/PropelParamConverterTest.php index ab10e65..ec52bb1 100644 --- a/Tests/Request/ParamConverter/PropelParamConverterTest.php +++ b/Tests/Request/ParamConverter/PropelParamConverterTest.php @@ -290,12 +290,17 @@ class PropelParamConverterTest extends TestCase $this->assertEquals($nb + 1, $this->con->getQueryCount(), 'no new query to get the books'); } - public function testConfigurationReadFromRouteOptionsIfEmpty() + public function testConfigurationReadFromRequestAttributesIfEmpty() { $this->loadFixtures(); - $routes = new RouteCollection(); - $routes->add('test_route', new Route('/test/{authorId}', array(), array(), array( + $paramConverter = new PropelParamConverter(); + + $request = new Request(); + $request->attributes->add(array( + '_route' => 'test_route', + 'id' => 10, + 'author' => null, 'propel_converter' => array( 'author' => array( 'mapping' => array( @@ -303,23 +308,6 @@ class PropelParamConverterTest extends TestCase ), ), ), - ))); - - $router = $this->getMock('Symfony\Bundle\FrameworkBundle\Routing\Router', array(), array(), '', false); - $router - ->expects($this->once()) - ->method('getRouteCollection') - ->will($this->returnValue($routes)) - ; - - $paramConverter = new PropelParamConverter(); - $paramConverter->setRouter($router); - - $request = new Request(); - $request->attributes->add(array( - '_route' => 'test_route', - 'id' => 10, - 'author' => null, )); $configuration = new ParamConverter(array(