From 505e474dee119bfc5068b1269f1a5d0d3463a194 Mon Sep 17 00:00:00 2001 From: nikita2206 Date: Fri, 12 Dec 2014 18:28:54 +0300 Subject: [PATCH] [FrameworkBundle] Container parameters in Route#condition --- UPGRADE-2.7.md | 17 +++++++++++++++++ .../Bundle/FrameworkBundle/Routing/Router.php | 1 + .../Tests/Routing/RouterTest.php | 4 +++- .../Bundle/FrameworkBundle/composer.json | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 UPGRADE-2.7.md diff --git a/UPGRADE-2.7.md b/UPGRADE-2.7.md new file mode 100644 index 0000000000..4900510a62 --- /dev/null +++ b/UPGRADE-2.7.md @@ -0,0 +1,17 @@ +UPGRADE FROM 2.6 to 2.7 +======================= + +### Router + + * Route conditions now support container parameters which + can be injected into condition using `%parameter%` notation. + Due to the fact that it works by replacing all parameters + with their corresponding values before passing condition + expression for compilation there can be BC breaks where you + could already have used percentage symbols. Single percentage symbol + usage is not affected in any way. Conflicts may occur where + you might have used `%` as a modulo operator, here's an example: + `foo%bar%2` which would be compiled to `$foo % $bar % 2` in 2.6 + but in 2.7 you would get an error if `bar` parameter + doesn't exist or unexpected result otherwise. + diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php index cee502d404..edfc41c2a7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php @@ -95,6 +95,7 @@ class Router extends BaseRouter implements WarmableInterface $route->setPath($this->resolve($route->getPath())); $route->setHost($this->resolve($route->getHost())); + $route->setCondition($this->resolve($route->getCondition())); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php index 0d3dab8488..330e0659ca 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php @@ -28,16 +28,18 @@ class RouterTest extends \PHPUnit_Framework_TestCase ), array( '_locale' => 'en|es', - ) + ), array(), '', array(), array(), '"%foo%" == "bar"' )); $sc = $this->getServiceContainer($routes); $sc->setParameter('locale', 'es'); + $sc->setParameter('foo', 'bar'); $router = new Router($sc, 'foo'); $this->assertSame('/en', $router->generate('foo', array('_locale' => 'en'))); $this->assertSame('/', $router->generate('foo', array('_locale' => 'es'))); + $this->assertSame('"bar" == "bar"', $router->getRouteCollection()->get('foo')->getCondition()); } public function testDefaultsPlaceholders() diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 454f429d80..b22feb2ddc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -23,7 +23,7 @@ "symfony/http-foundation": "~2.4.9|~2.5,>=2.5.4", "symfony/http-kernel": "~2.6", "symfony/filesystem": "~2.3", - "symfony/routing": "~2.2", + "symfony/routing": "~2.5", "symfony/security-core": "~2.6", "symfony/security-csrf": "~2.6", "symfony/stopwatch": "~2.3",