Skip to content

Commit d0022e3

Browse files
committed
merged branch Tobion/deprecation-trigger (PR #7266)
This PR was merged into the 2.2 branch. Commits ------- c0687cd remove() should not use deprecated getParent() so it does not trigger deprecation internally 708c0d3 adjust routing tests to not use prefix in addCollection 6180c5b add test for uniqueness of resources c0de07b added tests for addDefaults, addRequirements, addOptions 0a1cfcd adjust RouteCollectionTest for the addCollection change and refactor the tests to only skip the part that really needs the config component ea694e4 added tests for remove() that wasnt covered yet and special route name 9e2bcb5 refactor interator test that was still assuming a tree ceb9ab4 adjust tests to no use addPrefix with options 2b8bf6b adjusted tests to not use RouteCollection::getPrefix acff735 [Routing] trigger deprecation warning for deprecated features that will be removed in 2.3 Discussion ---------- [2.2][Routing] Trigger deprecation and refactor tests to not use deprecated methods | Q | A | ------------- | --- | Bug fix? | [yes] | New feature? | [no] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [yes] | License | MIT @fabpot please don't squash because it also added new tests
2 parents 5e3756f + c0687cd commit d0022e3

File tree

5 files changed

+127
-92
lines changed

5 files changed

+127
-92
lines changed

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public function __clone()
6565
*/
6666
public function getParent()
6767
{
68+
trigger_error('getParent() is deprecated since version 2.2 and will be removed in 2.3. There is no substitution ' .
69+
'because RouteCollection is not tree structure anymore.', E_USER_DEPRECATED);
70+
6871
return $this->parent;
6972
}
7073

@@ -77,6 +80,9 @@ public function getParent()
7780
*/
7881
public function getRoot()
7982
{
83+
trigger_error('getRoot() is deprecated since version 2.2 and will be removed in 2.3. There is no substitution ' .
84+
'because RouteCollection is not tree structure anymore.', E_USER_DEPRECATED);
85+
8086
$parent = $this;
8187
while ($parent->getParent()) {
8288
$parent = $parent->getParent();
@@ -157,7 +163,10 @@ public function get($name)
157163
public function remove($name)
158164
{
159165
// just for BC
160-
$root = $this->getRoot();
166+
$root = $this;
167+
while ($root->parent) {
168+
$root = $root->parent;
169+
}
161170

162171
foreach ((array) $name as $n) {
163172
unset($root->routes[$n]);
@@ -184,6 +193,8 @@ public function addCollection(RouteCollection $collection)
184193
// this is to keep BC
185194
$numargs = func_num_args();
186195
if ($numargs > 1) {
196+
trigger_error('addCollection() should only be used with a single parameter. The params $prefix, $defaults, $requirements and $options ' .
197+
'are deprecated since version 2.2 and will be removed in 2.3. Use addPrefix() and addOptions() instead.', E_USER_DEPRECATED);
187198
$collection->addPrefix($this->prefix . func_get_arg(1));
188199
if ($numargs > 2) {
189200
$collection->addDefaults(func_get_arg(2));
@@ -232,7 +243,13 @@ public function addPrefix($prefix, array $defaults = array(), array $requirement
232243
$this->prefix = '/' . $prefix . $this->prefix;
233244

234245
// this is to keep BC
235-
$options = func_num_args() > 3 ? func_get_arg(3) : array();
246+
if (func_num_args() > 3) {
247+
trigger_error('The fourth parameter ($options) of addPrefix() is deprecated since version 2.2 and will be removed in 2.3. ' .
248+
'Use addOptions() instead.', E_USER_DEPRECATED);
249+
$options = func_get_arg(3);
250+
} else {
251+
$options = array();
252+
}
236253

237254
foreach ($this->routes as $route) {
238255
$route->setPath('/' . $prefix . $route->getPath());
@@ -251,6 +268,9 @@ public function addPrefix($prefix, array $defaults = array(), array $requirement
251268
*/
252269
public function getPrefix()
253270
{
271+
trigger_error('getPrefix() is deprecated since version 2.2 and will be removed in 2.3. The method suggests that ' .
272+
'all routes in the collection would have this prefix, which is not necessarily true.', E_USER_DEPRECATED);
273+
254274
return $this->prefix;
255275
}
256276

src/Symfony/Component/Routing/Tests/Matcher/Dumper/ApacheMatcherDumperTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ private function getRouteCollection()
150150
$route3 = new Route('/route3', array(), array(), array(), 'b.example.com');
151151
$collection2->add('route3', $route3);
152152

153-
$collection1->addCollection($collection2, '/c2');
153+
$collection2->addPrefix('/c2');
154+
$collection1->addCollection($collection2);
154155

155156
$route4 = new Route('/route4', array(), array(), array(), 'a.example.com');
156157
$collection1->add('route4', $route4);

src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,17 @@ public function getRouteCollections()
118118
$collection1->add('overridden', new Route('/overridden1'));
119119
$collection1->add('foo1', new Route('/{foo}'));
120120
$collection1->add('bar1', new Route('/{bar}'));
121+
$collection1->addPrefix('/b\'b');
121122
$collection2 = new RouteCollection();
122-
$collection2->addCollection($collection1, '/b\'b');
123+
$collection2->addCollection($collection1);
123124
$collection2->add('overridden', new Route('/{var}', array(), array('var' => '.*')));
124125
$collection1 = new RouteCollection();
125126
$collection1->add('foo2', new Route('/{foo1}'));
126127
$collection1->add('bar2', new Route('/{bar1}'));
127-
$collection2->addCollection($collection1, '/b\'b');
128-
$collection->addCollection($collection2, '/a');
128+
$collection1->addPrefix('/b\'b');
129+
$collection2->addCollection($collection1);
130+
$collection2->addPrefix('/a');
131+
$collection->addCollection($collection2);
129132

130133
// overridden through addCollection() and multiple sub-collections with no own prefix
131134
$collection1 = new RouteCollection();
@@ -137,23 +140,25 @@ public function getRouteCollections()
137140
$collection3->add('hey', new Route('/hey/'));
138141
$collection2->addCollection($collection3);
139142
$collection1->addCollection($collection2);
140-
$collection->addCollection($collection1, '/multi');
143+
$collection1->addPrefix('/multi');
144+
$collection->addCollection($collection1);
141145

142146
// "dynamic" prefix
143147
$collection1 = new RouteCollection();
144148
$collection1->add('foo3', new Route('/{foo}'));
145149
$collection1->add('bar3', new Route('/{bar}'));
146-
$collection2 = new RouteCollection();
147-
$collection2->addCollection($collection1, '/b');
148-
$collection->addCollection($collection2, '/{_locale}');
150+
$collection1->addPrefix('/b');
151+
$collection1->addPrefix('{_locale}');
152+
$collection->addCollection($collection1);
149153

150154
// route between collections
151155
$collection->add('ababa', new Route('/ababa'));
152156

153157
// collection with static prefix but only one route
154158
$collection1 = new RouteCollection();
155159
$collection1->add('foo4', new Route('/{foo}'));
156-
$collection->addCollection($collection1, '/aba');
160+
$collection1->addPrefix('/aba');
161+
$collection->addCollection($collection1);
157162

158163
// prefix and host
159164

@@ -215,10 +220,12 @@ public function getRouteCollections()
215220
$collection2->add('b', new Route('/{var}'));
216221
$collection3 = new RouteCollection();
217222
$collection3->add('c', new Route('/{var}'));
218-
219-
$collection2->addCollection($collection3, '/c');
220-
$collection1->addCollection($collection2, '/b');
221-
$collection->addCollection($collection1, '/a');
223+
$collection3->addPrefix('/c');
224+
$collection2->addCollection($collection3);
225+
$collection2->addPrefix('/b');
226+
$collection1->addCollection($collection2);
227+
$collection1->addPrefix('/a');
228+
$collection->addCollection($collection1);
222229

223230
/* test case 2 */
224231

src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,29 +130,21 @@ public function testMatch()
130130

131131
public function testMatchWithPrefixes()
132132
{
133-
$collection1 = new RouteCollection();
134-
$collection1->add('foo', new Route('/{foo}'));
135-
136-
$collection2 = new RouteCollection();
137-
$collection2->addCollection($collection1, '/b');
138-
139133
$collection = new RouteCollection();
140-
$collection->addCollection($collection2, '/a');
134+
$collection->add('foo', new Route('/{foo}'));
135+
$collection->addPrefix('/b');
136+
$collection->addPrefix('/a');
141137

142138
$matcher = new UrlMatcher($collection, new RequestContext());
143139
$this->assertEquals(array('_route' => 'foo', 'foo' => 'foo'), $matcher->match('/a/b/foo'));
144140
}
145141

146142
public function testMatchWithDynamicPrefix()
147143
{
148-
$collection1 = new RouteCollection();
149-
$collection1->add('foo', new Route('/{foo}'));
150-
151-
$collection2 = new RouteCollection();
152-
$collection2->addCollection($collection1, '/b');
153-
154144
$collection = new RouteCollection();
155-
$collection->addCollection($collection2, '/{_locale}');
145+
$collection->add('foo', new Route('/{foo}'));
146+
$collection->addPrefix('/b');
147+
$collection->addPrefix('/{_locale}');
156148

157149
$matcher = new UrlMatcher($collection, new RequestContext());
158150
$this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo'));

0 commit comments

Comments
 (0)