Skip to content
This repository
Browse code

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...
commit 6463c9919cedade897ab2bbf9bfc04afa716d61b 2 parents 16405f9 + 4b86765
Fabien Potencier authored October 05, 2012
8  src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
@@ -114,6 +114,14 @@ private function resolveString($value)
114 114
     {
115 115
         $container = $this->container;
116 116
 
  117
+        if (is_array($value)) {
  118
+            foreach ($value as $key => $val) {
  119
+                $value[$key] = $this->resolveString($val);
  120
+            }
  121
+
  122
+            return $value;
  123
+        }
  124
+
117 125
         if (null === $value || false === $value || true === $value || is_object($value)) {
118 126
             return $value;
119 127
         }
10  src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php
@@ -27,6 +27,8 @@ public function testDefaultsPlaceholders()
27 27
                 'foo'    => 'before_%parameter.foo%',
28 28
                 'bar'    => '%parameter.bar%_after',
29 29
                 'baz'    => '%%unescaped%%',
  30
+                'boo'    => array('%parameter%', '%%escaped_parameter%%', array('%bee_parameter%', 'bee')),
  31
+                'bee'    => array('bee', 'bee'),
30 32
             ),
31 33
             array(
32 34
             )
@@ -39,6 +41,12 @@ public function testDefaultsPlaceholders()
39 41
         $sc->expects($this->at(3))->method('hasParameter')->will($this->returnValue(true));
40 42
         $sc->expects($this->at(4))->method('getParameter')->will($this->returnValue('bar'));
41 43
 
  44
+        $sc->expects($this->at(5))->method('hasParameter')->will($this->returnValue(true));
  45
+        $sc->expects($this->at(6))->method('getParameter')->will($this->returnValue('boo'));
  46
+
  47
+        $sc->expects($this->at(7))->method('hasParameter')->will($this->returnValue(true));
  48
+        $sc->expects($this->at(8))->method('getParameter')->will($this->returnValue('foo_bee'));
  49
+
42 50
         $router = new Router($sc, 'foo');
43 51
         $route = $router->getRouteCollection()->get('foo');
44 52
 
@@ -47,6 +55,8 @@ public function testDefaultsPlaceholders()
47 55
                 'foo' => 'before_foo',
48 56
                 'bar' => 'bar_after',
49 57
                 'baz' => '%unescaped%',
  58
+                'boo' => array('boo', '%escaped_parameter%', array('foo_bee', 'bee')),
  59
+                'bee' => array('bee', 'bee'),
50 60
             ),
51 61
             $route->getDefaults()
52 62
         );

0 notes on commit 6463c99

Please sign in to comment.
Something went wrong with that request. Please try again.