[FrameworkBundle][Routing] allow boolean container parameters for routes
This commit is contained in:
parent
d2e9a7051f
commit
21f4e38800
@ -17,6 +17,7 @@ CHANGELOG
|
|||||||
to the `session` section of the configuration
|
to the `session` section of the configuration
|
||||||
* Added support for Translator paths, Twig paths in translation commands.
|
* Added support for Translator paths, Twig paths in translation commands.
|
||||||
* Added support for PHP files with translations in translation commands.
|
* Added support for PHP files with translations in translation commands.
|
||||||
|
* Added support for boolean container parameters within routes.
|
||||||
|
|
||||||
4.2.0
|
4.2.0
|
||||||
-----
|
-----
|
||||||
|
@ -164,6 +164,10 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
|
|||||||
|
|
||||||
$resolved = ($this->paramFetcher)($match[1]);
|
$resolved = ($this->paramFetcher)($match[1]);
|
||||||
|
|
||||||
|
if (\is_bool($resolved)) {
|
||||||
|
$resolved = (string) (int) $resolved;
|
||||||
|
}
|
||||||
|
|
||||||
if (\is_string($resolved) || is_numeric($resolved)) {
|
if (\is_string($resolved) || is_numeric($resolved)) {
|
||||||
$this->collectedParameters[$match[1]] = $resolved;
|
$this->collectedParameters[$match[1]] = $resolved;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class RouterTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testConstructThrowsOnNonSymfonyNorPsr11Container()
|
public function testConstructThrowsOnNonSymfonyNorPsr11Container()
|
||||||
{
|
{
|
||||||
new Router($this->getMockBuilder(ContainerInterface::class)->getMock(), 'foo');
|
new Router($this->createMock(ContainerInterface::class), 'foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGenerateWithServiceParam()
|
public function testGenerateWithServiceParam()
|
||||||
@ -447,6 +447,24 @@ class RouterTest extends TestCase
|
|||||||
$this->assertEquals([new ContainerParametersResource(['locale' => 'en'])], $routeCollection->getResources());
|
$this->assertEquals([new ContainerParametersResource(['locale' => 'en'])], $routeCollection->getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBooleanContainerParametersWithinRouteCondition()
|
||||||
|
{
|
||||||
|
$routes = new RouteCollection();
|
||||||
|
|
||||||
|
$route = new Route('foo');
|
||||||
|
$route->setCondition('%parameter.true% or %parameter.false%');
|
||||||
|
|
||||||
|
$routes->add('foo', $route);
|
||||||
|
|
||||||
|
$sc = $this->getPsr11ServiceContainer($routes);
|
||||||
|
$parameters = $this->getParameterBag(['parameter.true' => true, 'parameter.false' => false]);
|
||||||
|
|
||||||
|
$router = new Router($sc, 'foo', [], null, $parameters);
|
||||||
|
$route = $router->getRouteCollection()->get('foo');
|
||||||
|
|
||||||
|
$this->assertSame('1 or 0', $route->getCondition());
|
||||||
|
}
|
||||||
|
|
||||||
public function getNonStringValues()
|
public function getNonStringValues()
|
||||||
{
|
{
|
||||||
return [[null], [false], [true], [new \stdClass()], [['foo', 'bar']], [[[]]]];
|
return [[null], [false], [true], [new \stdClass()], [['foo', 'bar']], [[[]]]];
|
||||||
|
Reference in New Issue
Block a user