[FrameworkBundle] Container parameters in Route#condition

This commit is contained in:
nikita2206 2014-12-12 18:28:54 +03:00 committed by Fabien Potencier
parent 550ca9d987
commit 505e474dee
4 changed files with 22 additions and 2 deletions

17
UPGRADE-2.7.md Normal file
View File

@ -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.

View File

@ -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()));
}
}

View File

@ -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()

View File

@ -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",