Skip to content
Permalink
Browse files

feature #30379 [FrameworkBundle][Routing] allow boolean container par…

…ameters for routes (dmaicher)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[FrameworkBundle][Routing] allow boolean container parameters for routes

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30366
| License       | MIT
| Doc PR        | symfony/symfony-docs#11059

This fixes #30366 and adds support for boolean container parameters in route conditions, defaults etc.

Commits
-------

21f4e38 [FrameworkBundle][Routing] allow boolean container parameters for routes
  • Loading branch information...
fabpot committed Mar 4, 2019
2 parents 1e94c50 + 21f4e38 commit ec8033f4a9334e7687f5b3958ad4d80c7f9ee8ad
@@ -17,6 +17,7 @@ CHANGELOG
to the `session` section of the configuration
* Added support for Translator paths, Twig paths in translation commands.
* Added support for PHP files with translations in translation commands.
* Added support for boolean container parameters within routes.

4.2.0
-----
@@ -164,6 +164,10 @@ private function resolve($value)
$resolved = ($this->paramFetcher)($match[1]);
if (\is_bool($resolved)) {
$resolved = (string) (int) $resolved;
}
if (\is_string($resolved) || is_numeric($resolved)) {
$this->collectedParameters[$match[1]] = $resolved;
@@ -27,7 +27,7 @@ class RouterTest extends TestCase
*/
public function testConstructThrowsOnNonSymfonyNorPsr11Container()
{
new Router($this->getMockBuilder(ContainerInterface::class)->getMock(), 'foo');
new Router($this->createMock(ContainerInterface::class), 'foo');
}
public function testGenerateWithServiceParam()
@@ -447,6 +447,24 @@ public function testGetRouteCollectionAddsContainerParametersResourceWithSfConta
$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()
{
return [[null], [false], [true], [new \stdClass()], [['foo', 'bar']], [[[]]]];

0 comments on commit ec8033f

Please sign in to comment.
You can’t perform that action at this time.