Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ec8033f

Browse filesBrowse files
committed
feature #30379 [FrameworkBundle][Routing] allow boolean container parameters 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
2 parents 1e94c50 + 21f4e38 commit ec8033f
Copy full SHA for ec8033f

File tree

3 files changed

+24
-1
lines changed
Filter options

3 files changed

+24
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CHANGELOG
1717
to the `session` section of the configuration
1818
* Added support for Translator paths, Twig paths in translation commands.
1919
* Added support for PHP files with translations in translation commands.
20+
* Added support for boolean container parameters within routes.
2021

2122
4.2.0
2223
-----

‎src/Symfony/Bundle/FrameworkBundle/Routing/Router.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ private function resolve($value)
164164

165165
$resolved = ($this->paramFetcher)($match[1]);
166166

167+
if (\is_bool($resolved)) {
168+
$resolved = (string) (int) $resolved;
169+
}
170+
167171
if (\is_string($resolved) || is_numeric($resolved)) {
168172
$this->collectedParameters[$match[1]] = $resolved;
169173

‎src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php
+19-1Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class RouterTest extends TestCase
2727
*/
2828
public function testConstructThrowsOnNonSymfonyNorPsr11Container()
2929
{
30-
new Router($this->getMockBuilder(ContainerInterface::class)->getMock(), 'foo');
30+
new Router($this->createMock(ContainerInterface::class), 'foo');
3131
}
3232

3333
public function testGenerateWithServiceParam()
@@ -447,6 +447,24 @@ public function testGetRouteCollectionAddsContainerParametersResourceWithSfConta
447447
$this->assertEquals([new ContainerParametersResource(['locale' => 'en'])], $routeCollection->getResources());
448448
}
449449

450+
public function testBooleanContainerParametersWithinRouteCondition()
451+
{
452+
$routes = new RouteCollection();
453+
454+
$route = new Route('foo');
455+
$route->setCondition('%parameter.true% or %parameter.false%');
456+
457+
$routes->add('foo', $route);
458+
459+
$sc = $this->getPsr11ServiceContainer($routes);
460+
$parameters = $this->getParameterBag(['parameter.true' => true, 'parameter.false' => false]);
461+
462+
$router = new Router($sc, 'foo', [], null, $parameters);
463+
$route = $router->getRouteCollection()->get('foo');
464+
465+
$this->assertSame('1 or 0', $route->getCondition());
466+
}
467+
450468
public function getNonStringValues()
451469
{
452470
return [[null], [false], [true], [new \stdClass()], [['foo', 'bar']], [[[]]]];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.