[FrameworkBundle] Container parameters in Route#condition
This commit is contained in:
parent
550ca9d987
commit
505e474dee
|
@ -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.
|
||||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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",
|
||||
|
|
Reference in New Issue