8000 [Routing] remove deprecated features from routing · symfony/symfony@86278cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 86278cd

Browse files
committed
[Routing] remove deprecated features from routing
1 parent ceefea8 commit 86278cd

File tree

13 files changed

+3
-236
lines changed

13 files changed

+3
-236
lines changed

src/Symfony/Component/Routing/Annotation/Route.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,6 @@ public function __construct(array $data)
5454
}
5555
}
5656

57-
/**
58-
* @deprecated since version 2.2, to be removed in 3.0. Use setPath instead.
59-
*/
60-
public function setPattern($pattern)
61-
{
62-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.2 and will be removed in 3.0. Use the setPath() method instead and use the "path" option instead of the "pattern" option in the route definition.', E_USER_DEPRECATED);
63-
64-
$this->path = $pattern;
65-
}
66-
67-
/**
68-
* @deprecated since version 2.2, to be removed in 3.0. Use getPath instead.
69-
*/
70-
public function getPattern()
71-
{
72-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.2 and will be removed in 3.0. Use the getPath() method instead and use the "path" option instead of the "pattern" option in the route definition.', E_USER_DEPRECATED);
73-
74-
return $this->path;
75-
}
76-
7757
public function setPath($path)
7858
{
7959
$this->path = $path;

src/Symfony/Component/Routing/Generator/UrlGenerator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
219219
$referenceType = self::ABSOLUTE_URL;
220220
$scheme = current($requiredSchemes);
221221
}
222-
} elseif (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) {
223-
// We do this for BC; to be removed if _scheme is not supported anymore
224-
$referenceType = self::ABSOLUTE_URL;
225-
$scheme = $req;
226222
}
227223

228224
if ($hostTokens) {

src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,8 @@ protected function getGlobals(\ReflectionClass $class)
220220
);
221221

222222
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
223-
// for BC reasons
224223
if (null !== $annot->getPath()) {
225224
$globals['path'] = $annot->getPath();
226-
} elseif (null !== $annot->getPattern()) {
227-
$globals['path'] = $annot->getPattern();
228225
}
229226

230227
if (null !== $annot->getRequirements()) {

src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,6 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
117117
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "path" attribute.', $path));
118118
}
119119

120-
if ($node->hasAttribute('pattern')) {
121-
if ($node->hasAttribute('path')) {
122-
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
123-
}
124-
125-
trigger_error('The "pattern" is deprecated since version 2.2 and will be removed in 3.0. Use the "path" option in the route definition instead.', E_USER_DEPRECATED);
126-
127-
$node->setAttribute('path', $node->getAttribute('pattern'));
128-
$node->removeAttribute('pattern');
129-
}
130-
131120
$schemes = preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
132121
$methods = preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);
133122

src/Symfony/Component/Routing/Loader/YamlFileLoader.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class YamlFileLoader extends FileLoader
2929
{
3030
private static $availableKeys = array(
31-
'resource', 'type', 'prefix', 'pattern', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', 'condition',
31+
'resource', 'type', 'prefix', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', 'condition',
3232
);
3333
private $yamlParser;
3434

@@ -76,17 +76,6 @@ public function load($file, $type = null)
7676
}
7777

7878
foreach ($config as $name => $config) {
79-
if (isset($config['pattern'])) {
80-
if (isset($config['path'])) {
81-
throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
82-
}
83-
84-
trigger_error('The "pattern" is deprecated since version 2.2 and will be removed in 3.0. Use the "path" option in the route definition instead.', E_USER_DEPRECATED);
85-
86-
$config['path'] = $config['pattern'];
87-
unset($config['pattern']);
88-
}
89-
9079
$this->validate($config, $name, $path);
9180

9281
if (isset($config['resource'])) {

src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
<xsd:attribute name="id" type="xsd:string" use="required" />
4040
<xsd:attribute name="path" type="xsd:string" />
41-
<xsd:attribute name="pattern" type="xsd:string" />
4241
<xsd:attribute name="host" type="xsd:string" />
4342
<xsd:attribute name="schemes" type="xsd:string" />
4443
<xsd:attribute name="methods" type="xsd:string" />

src/Symfony/Component/Routing/Route.php

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,8 @@ public function __construct($path, array $defaults = array(), array $requirement
9191
$this->setRequirements($requirements);
9292
$this->setOptions($options);
9393
$this->setHost($host);
94-
// The conditions make sure that an initial empty $schemes/$methods does not override the corresponding requirement.
95-
// They can be removed when the BC layer is removed.
96-
if ($schemes) {
97-
$this->setSchemes($schemes);
98-
}
99-
if ($methods) {
100-
$this->setMethods($methods);
101-
}
94+
$this->setSchemes($schemes);
95+
$this->setMethods($methods);
10296
$this->setCondition($condition);
10397
}
10498

@@ -142,38 +136,6 @@ public function unserialize($serialized)
142136
}
143137
}
144138

145-
/**
146-
* Returns the pattern for the path.
147-
*
148-
* @return string The pattern
149-
*
150-
* @deprecated since version 2.2, to be removed in 3.0. Use getPath instead.
151-
*/
152-
public function getPattern()
153-
{
154-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.2 and will be removed in 3.0. Use the getPath() method instead.', E_USER_DEPRECATED);
155-
156-
return $this->path;
157-
}
158-
159-
/**
160-
* Sets the pattern for the path.
161-
*
162-
* This method implements a fluent interface.
163-
*
164-
* @param string $pattern The path pattern
165-
*
166-
* @return Route The current Route instance
167-
*
168-
* @deprecated since version 2.2, to be removed in 3.0. Use setPath instead.
169-
*/
170-
public function setPattern($pattern)
171-
{
172-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.2 and will be removed in 3.0. Use the setPath() method instead.', E_USER_DEPRECATED);
173-
174-
return $this->setPath($pattern);
175-
}
176-
177139
/**
178140
* Returns the pattern for the path.
179141
*
@@ -254,14 +216,6 @@ public function getSchemes()
254216
public function setSchemes($schemes)
255217
{
256218
$this->schemes = array_map('strtolower', (array) $schemes);
257-
258-
// this is to keep BC and will be removed in a future version
259-
if ($this->schemes) {
260-
$this->requirements['_scheme'] = implode('|', $this->schemes);
261-
} else {
262-
unset($this->requirements['_scheme']);
263-
}
264-
265219
$this->compiled = null;
266220

267221
return $this;
@@ -303,14 +257,6 @@ public function getMethods()
303257
public function setMethods($methods)
304258
{
305259
$this->methods = array_map('strtoupper', (array) $methods);
306-
307-
// this is to keep BC and will be removed in a future version
308-
if ($this->methods) {
309-
$this->requirements['_method'] = implode('|', $this->methods);
310-
} else {
311-
unset($this->requirements['_method']);
312-
}
313-
314260
$this->compiled = null;
315261

316262
return $this;
@@ -548,12 +494,6 @@ public function addRequirements(array $requirements)
548494
*/
549495
public function getRequirement($key)
550496
{
551-
if ('_scheme' === $key) {
552-
trigger_error('The "_scheme" requirement is deprecated since version 2.2 and will be removed in 3.0. Use getSchemes() instead.', E_USER_DEPRECATED);
553-
} elseif ('_method' === $key) {
554-
trigger_error('The "_method" requirement is deprecated since version 2.2 and will be removed in 3.0. Use getMethods() instead.', E_USER_DEPRECATED);
555-
}
556-
557497
return isset($this->requirements[$key]) ? $this->requirements[$key] : null;
558498
}
559499

@@ -653,17 +593,6 @@ private function sanitizeRequirement($key, $regex)
653593
throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" cannot be empty.', $key));
654594
}
655595

656-
// this is to keep BC and will be removed in a future version
657-
if ('_scheme' === $key) {
658-
trigger_error('The "_scheme" requirement is deprecated since version 2.2 and will be removed in 3.0. Use the setSchemes() method instead or the "schemes" option in the route definition.', E_USER_DEPRECATED);
659-
660-
$this->setSchemes(explode('|', $regex));
661-
} elseif ('_method' === $key) {
662-
trigger_error('The "_method" requirement is deprecated since version 2.2 and will be removed in 3.0. Use the setMethods() method instead or the "methods" option in the route definition.', E_USER_DEPRECATED);
663-
664-
$this->setMethods(explode('|', $regex));
665-
}
666-
667596
return $regex;
668597
}
669598
}

src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,4 @@ public function getValidParameters()
4646
array('condition', 'context.getMethod() == "GET"', 'getCondition'),
4747
);
4848
}
49-
50-
public function testLegacyGetPattern()
51-
{
52-
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
53-
54-
$route = new Route(array('value' => '/Blog'));
55-
$this->assertEquals($route->getPattern(), '/Blog');
56-
}
5749
}

src/Symfony/Component/Routing/Tests/Fixtures/legacy_validpattern.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Symfony/Component/Routing/Tests/Fixtures/legacy_validpattern.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,6 @@ public function testLoadWithRoute()
4545
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
4646
}
4747

48-
public function testLegacyRouteDefinitionLoading()
49-
{
50-
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
51-
52-
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
53-
$routeCollection = $loader->load('legacy_validpattern.xml');
54-
$route = $routeCollection->get('blog_show_legacy');
55-
56-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
57-
$this->assertSame('/blog/{slug}', $route->getPath());
58-
$this->assertSame('{locale}.example.com', $route->getHost());
59-
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
60-
$this->assertSame('\w+', $route->getRequirement('locale'));
61-
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
62-
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
63-
$this->assertEquals(array('https'), $route->getSchemes());
64-
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
65-
}
66-
6748
public function testLoadWithNamespacePrefix()
6849
{
6950
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));

src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,6 @@ public function testLoadWithRoute()
7979
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
8080
}
8181

82-
public function testLegacyRouteDefinitionLoading()
83-
{
84-
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
85-
86-
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
87-
$routeCollection = $loader->load('legacy_validpattern.yml');
88-
$route = $routeCollection->get('blog_show_legacy');
89-
90-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
91-
$this->assertSame('/blog/{slug}', $route->getPath());
92-
$this->assertSame('{locale}.example.com', $route->getHost());
93-
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
94-
$this->assertSame('\w+', $route->getRequirement('locale'));
95-
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
96-
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
97-
$this->assertEquals(array('https'), $route->getSchemes());
98-
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
99-
}
100-
10182
public function testLoadWithResource()
10283
{
10384
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));

src/Symfony/Component/Routing/Tests/RouteTest.php

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,6 @@ public function testScheme()
164164
$this->assertTrue($route->hasScheme('httpS'));
165165
}
166166

167-
public function testLegacySchemeRequirement()
168-
{
169-
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
170-
171-
$route = new Route('/');
172-
$route->setRequirement('_scheme', 'http|https');
173-
$this->assertEquals('http|https', $route->getRequirement('_scheme'));
174-
$this->assertEquals(array('http', 'https'), $route->getSchemes());
175-
$this->assertTrue($route->hasScheme('https'));
176-
$this->assertTrue($route->hasScheme('http'));
177-
$this->assertFalse($route->hasScheme('ftp'));
178-
$route->setSchemes(array('hTTp'));
179-
$this->assertEquals('http', $route->getRequirement('_scheme'));
180-
$route->setSchemes(array());
181-
$this->assertNull($route->getRequirement('_scheme'));
182-
}
183-
184167
public function testMethod()
185168
{
186169
$route = new Route('/');
@@ -191,20 +174,6 @@ public function testMethod()
191174
$this->assertEquals(array('GET', 'POST'), $route->getMethods(), '->setMethods() accepts an array of methods and uppercases them');
192175
}
193176

194-
public function testLegacyMethodRequirement()
195-
{
196-
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
197-
198-
$route = new Route('/');
199-
$route->setRequirement('_method', 'GET|POST');
200-
$this->assertEquals('GET|POST', $route->getRequirement('_method'));
201-
$this->assertEquals(array('GET', 'POST'), $route->getMethods());
202-
$route->setMethods(array('gEt'));
203-
$this->assertEquals('GET', $route->getRequirement('_method'));
204-
$route->setMethods(array());
205-
$this->assertNull($route->getRequirement('_method'));
206-
}
207-
208177
public function testCondition()
209178
{
210179
$route = new Route('/');
@@ -222,17 +191,6 @@ public function testCompile()
222191
$this->assertNotSame($compiled, $route->compile(), '->compile() recompiles if the route was modified');
223192
}
224193

225-
public function testLegacyPattern()
226-
{
227-
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
228-
229-
$route = new Route('/{foo}');
230-
$this->assertEquals('/{foo}', $route->getPattern());
231-
232-
$route->setPattern('/bar');
233-
$this->assertEquals('/bar', $route->getPattern());
234-
}
235-
236194
public function testSerialize()
237195
{
238196
$route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\d+'));

0 commit comments

Comments
 (0)
0