10000 [FrameworkBundle] Container parameters in Route#condition · symfony/symfony@505e474 · GitHub
[go: up one dir, main page]

Skip to content

Commit 505e474

Browse files
nikita2206fabpot
authored andcommitted
[FrameworkBundle] Container parameters in Route#condition
1 parent 550ca9d commit 505e474

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

UPGRADE-2.7.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
UPGRADE FROM 2.6 to 2.7
2+
=======================
3+
4+
### Router
5+
6+
* Route conditions now support container parameters which
7+
can be injected into condition using `%parameter%` notation.
8+
Due to the fact that it works by replacing all parameters
9+
with their corresponding values before passing condition
10+
expression for compilation there can be BC breaks where you
11+
could already have used percentage symbols. Single percentage symbol
12+
usage is not affected in any way. Conflicts may occur where
13+
you might have used `%` as a modulo operator, here's an example:
14+
`foo%bar%2` which would be compiled to `$foo % $bar % 2` in 2.6
15+
but in 2.7 you would get an error if `bar` parameter
16+
doesn't exist or unexpected result otherwise.
17+

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private function resolveParameters(RouteCollection $collection)
9595

9696
$route->setPath($this->resolve($route->getPath()));
9797
$route->setHost($this->resolve($route->getHost()));
98+
$route->setCondition($this->resolve($route->getCondition()));
9899
}
99100
}
100101

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ public function testGenerateWithServiceParam()
2828
),
2929
array(
3030
'_locale' => 'en|es',
31-
)
31+
), array(), '', array(), array(), '"%foo%" == "bar"'
3232
));
3333

3434
$sc = $this->getServiceContainer($routes);
3535
$sc->setParameter('locale', 'es');
36+
$sc->setParameter('foo', 'bar');
3637

3738
$router = new Router($sc, 'foo');
3839

3940
$this->assertSame('/en', $router->generate('foo', array('_locale' => 'en')));
4041
$this->assertSame('/', $router->generate('foo', array('_locale' => 'es')));
42+
$this->assertSame('"bar" == "bar"', $router->getRouteCollection()->get('foo')->getCondition());
4143
}
4244

4345
public function testDefaultsPlaceholders()

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/http-foundation": "~2.4.9|~2.5,>=2.5.4",
2424
"symfony/http-kernel": "~2.6",
2525
"symfony/filesystem": "~2.3",
26-
"symfony/routing": "~2.2",
26+
"symfony/routing": "~2.5",
2727
"symfony/security-core": "~2.6",
2828
"symfony/security-csrf": "~2.6",
2929
"symfony/stopwatch": "~2.3",

0 commit comments

Comments
 (0)
0