Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 19 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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']], [[[]]]];
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy