Permalink
Browse files

merged branch docteurklein/fix-router-resolve-string (PR #4995)

This PR was merged into the master branch.

Commits
-------

4b86765 [FrameworkBundle] recursively resolve container parameter placeholders for arrays in router _defaults

Discussion
----------

[2.2] [FrameworkBundle] avoid trying to resolve container placeholders on arrays on router _defaults

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: ~
Todo: ~
License of the code: MIT
Documentation PR: ~

Permits to pass arrays in route `_defaults`.

---------------------------------------------------------------------------

by stof at 2012-07-20T13:07:36Z

This seems weird. An array could contain parameters in it.

---------------------------------------------------------------------------

by docteurklein at 2012-07-20T13:17:00Z

@stof An object too then, no ? Why accepting objects but not arrays ? Would you propose to recursively resolve array values ?

---------------------------------------------------------------------------

by stof at 2012-07-20T13:31:06Z

@docteurklein Resolving array values recursively would be consistent with the way the DIC parameters are resolved. I don't really see how you would resolve objects (and btw, it is pretty much an edge case as you cannot really put an object in your routes if you define them in your YAML or XML config files or with annotations)

---------------------------------------------------------------------------

by docteurklein at 2012-07-20T13:36:43Z

@stof I agree. I can manage recursive array resolving if needed.

---------------------------------------------------------------------------

by fabpot at 2012-07-23T13:58:07Z

Can you squash your commits before I merge? Thanks.

---------------------------------------------------------------------------

by docteurklein at 2012-07-23T14:39:17Z

@fabpot  done.
  • Loading branch information...
2 parents 16405f9 + 4b86765 commit 6463c9919cedade897ab2bbf9bfc04afa716d61b @fabpot fabpot committed Oct 5, 2012
View
8 src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
@@ -114,6 +114,14 @@ private function resolveString($value)
{
$container = $this->container;
+ if (is_array($value)) {
+ foreach ($value as $key => $val) {
+ $value[$key] = $this->resolveString($val);
+ }
+
+ return $value;
+ }
+
if (null === $value || false === $value || true === $value || is_object($value)) {
return $value;
}
View
10 src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php
@@ -27,6 +27,8 @@ public function testDefaultsPlaceholders()
'foo' => 'before_%parameter.foo%',
'bar' => '%parameter.bar%_after',
'baz' => '%%unescaped%%',
+ 'boo' => array('%parameter%', '%%escaped_parameter%%', array('%bee_parameter%', 'bee')),
+ 'bee' => array('bee', 'bee'),
),
array(
)
@@ -39,6 +41,12 @@ public function testDefaultsPlaceholders()
$sc->expects($this->at(3))->method('hasParameter')->will($this->returnValue(true));
$sc->expects($this->at(4))->method('getParameter')->will($this->returnValue('bar'));
+ $sc->expects($this->at(5))->method('hasParameter')->will($this->returnValue(true));
+ $sc->expects($this->at(6))->method('getParameter')->will($this->returnValue('boo'));
+
+ $sc->expects($this->at(7))->method('hasParameter')->will($this->returnValue(true));
+ $sc->expects($this->at(8))->method('getParameter')->will($this->returnValue('foo_bee'));
+
$router = new Router($sc, 'foo');
$route = $router->getRouteCollection()->get('foo');
@@ -47,6 +55,8 @@ public function testDefaultsPlaceholders()
'foo' => 'before_foo',
'bar' => 'bar_after',
'baz' => '%unescaped%',
+ 'boo' => array('boo', '%escaped_parameter%', array('foo_bee', 'bee')),
+ 'bee' => array('bee', 'bee'),
),
$route->getDefaults()
);

0 comments on commit 6463c99

Please sign in to comment.