Read "propel_converter" options from request attributes (#449)
This commit is contained in:
parent
2330aa2e8a
commit
4df8ff614c
|
@ -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()];
|
||||
}
|
||||
|
|
|
@ -11,10 +11,6 @@
|
|||
<services>
|
||||
<service id="propel.converter.propel.orm" class="%propel.converter.propel.class%">
|
||||
<tag name="request.param_converter" converter="propel" priority="1" />
|
||||
|
||||
<call method="setRouter">
|
||||
<argument type="service" id="router" on-invalid="null" />
|
||||
</call>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue