feature #13396 [Routing] remove deprecations for 3.0 (Tobion)

This PR was merged into the 3.0-dev branch.

Discussion
----------

[Routing] remove deprecations for 3.0

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | no, but unrelated
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

f939fea [Routing] make path required again in the xsd
82d54fa [FramworkBundle] our tests now expect symfony 3.0 behavior for routing
4ca9ab3 [FrameworkBundle] remove deprecated routing features
86278cd [Routing] remove deprecated features from routing
This commit is contained in:
Tobias Schultze 2015-01-31 21:34:12 +01:00
commit 589179cfac
19 changed files with 11 additions and 259 deletions

View File

@ -180,9 +180,6 @@ class JsonDescriptor extends Descriptor
*/
protected function getRouteData(Route $route)
{
$requirements = $route->getRequirements();
unset($requirements['_scheme'], $requirements['_method']);
return array(
'path' => $route->getPath(),
'pathRegex' => $route->compile()->getRegex(),
@ -192,7 +189,7 @@ class JsonDescriptor extends Descriptor
'method' => $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY',
'class' => get_class($route),
'defaults' => $route->getDefaults(),
'requirements' => $requirements ?: 'NO CUSTOM',
'requirements' => $route->getRequirements() ?: 'NO CUSTOM',
'options' => $route->getOptions(),
);
}

View File

@ -49,9 +49,6 @@ class MarkdownDescriptor extends Descriptor
*/
protected function describeRoute(Route $route, array $options = array())
{
$requirements = $route->getRequirements();
unset($requirements['_scheme'], $requirements['_method']);
$output = '- Path: '.$route->getPath()
."\n".'- Path Regex: '.$route->compile()->getRegex()
."\n".'- Host: '.('' !== $route->getHost() ? $route->getHost() : 'ANY')
@ -60,7 +57,7 @@ class MarkdownDescriptor extends Descriptor
."\n".'- Method: '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY')
."\n".'- Class: '.get_class($route)
."\n".'- Defaults: '.$this->formatRouterConfig($route->getDefaults())
."\n".'- Requirements: '.($requirements ? $this->formatRouterConfig($requirements) : 'NO CUSTOM')
."\n".'- Requirements: '.($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM')
."\n".'- Options: '.$this->formatRouterConfig($route->getOptions());
$this->write(isset($options['name'])

View File

@ -70,9 +70,6 @@ class TextDescriptor extends Descriptor
*/
protected function describeRoute(Route $route, array $options = array())
{
$requirements = $route->getRequirements();
unset($requirements['_scheme'], $requirements['_method']);
// fixme: values were originally written as raw
$description = array(
'<comment>Path</comment> '.$route->getPath(),
@ -83,7 +80,7 @@ class TextDescriptor extends Descriptor
'<comment>Method</comment> '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'),
'<comment>Class</comment> '.get_class($route),
'<comment>Defaults</comment> '.$this->formatRouterConfig($route->getDefaults()),
'<comment>Requirements</comment> '.($requirements ? $this->formatRouterConfig($requirements) : 'NO CUSTOM'),
'<comment>Requirements</comment> '.($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM'),
'<comment>Options</comment> '.$this->formatRouterConfig($route->getOptions()),
);

View File

@ -196,11 +196,9 @@ class XmlDescriptor extends Descriptor
}
}
$requirements = $route->getRequirements();
unset($requirements['_scheme'], $requirements['_method']);
if (count($requirements)) {
if (count($route->getRequirements())) {
$routeXML->appendChild($requirementsXML = $dom->createElement('requirements'));
foreach ($requirements as $attribute => $pattern) {
foreach ($route->getRequirements() as $attribute => $pattern) {
$requirementsXML->appendChild($requirementXML = $dom->createElement('requirement'));
$requirementXML->setAttribute('key', $attribute);
$requirementXML->appendChild(new \DOMText($pattern));

View File

@ -92,10 +92,6 @@ class Router extends BaseRouter implements WarmableInterface
}
foreach ($route->getRequirements() as $name => $value) {
if ('_scheme' === $name || '_method' === $name) {
continue; // ignore deprecated requirements to not trigger deprecation warnings
}
$route->setRequirement($name, $this->resolve($value));
}

View File

@ -23,7 +23,7 @@
"symfony/http-foundation": "~2.7|~3.0",
"symfony/http-kernel": "~2.7|~3.0",
"symfony/filesystem": "~2.7|~3.0",
"symfony/routing": "~2.7|~3.0",
"symfony/routing": "~3.0",
"symfony/security-core": "~2.7|~3.0",
"symfony/security-csrf": "~2.7|~3.0",
"symfony/stopwatch": "~2.7|~3.0",

View File

@ -54,26 +54,6 @@ class Route
}
}
/**
* @deprecated since version 2.2, to be removed in 3.0. Use setPath instead.
*/
public function setPattern($pattern)
{
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);
$this->path = $pattern;
}
/**
* @deprecated since version 2.2, to be removed in 3.0. Use getPath instead.
*/
public function getPattern()
{
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);
return $this->path;
}
public function setPath($path)
{
$this->path = $path;

View File

@ -219,10 +219,6 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
$referenceType = self::ABSOLUTE_URL;
$scheme = current($requiredSchemes);
}
} elseif (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) {
// We do this for BC; to be removed if _scheme is not supported anymore
$referenceType = self::ABSOLUTE_URL;
$scheme = $req;
}
if ($hostTokens) {

View File

@ -220,11 +220,8 @@ abstract class AnnotationClassLoader implements LoaderInterface
);
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
// for BC reasons
if (null !== $annot->getPath()) {
$globals['path'] = $annot->getPath();
} elseif (null !== $annot->getPattern()) {
$globals['path'] = $annot->getPattern();
}
if (null !== $annot->getRequirements()) {

View File

@ -113,21 +113,10 @@ class XmlFileLoader extends FileLoader
*/
protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
{
if ('' === ($id = $node->getAttribute('id')) || (!$node->hasAttribute('pattern') && !$node->hasAttribute('path'))) {
if ('' === ($id = $node->getAttribute('id')) || !$node->hasAttribute('path')) {
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "path" attribute.', $path));
}
if ($node->hasAttribute('pattern')) {
if ($node->hasAttribute('path')) {
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
}
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);
$node->setAttribute('path', $node->getAttribute('pattern'));
$node->removeAttribute('pattern');
}
$schemes = preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
$methods = preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);

View File

@ -28,7 +28,7 @@ use Symfony\Component\Config\Loader\FileLoader;
class YamlFileLoader extends FileLoader
{
private static $availableKeys = array(
'resource', 'type', 'prefix', 'pattern', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', 'condition',
'resource', 'type', 'prefix', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options', 'condition',
);
private $yamlParser;
@ -76,17 +76,6 @@ class YamlFileLoader extends FileLoader
}
foreach ($config as $name => $config) {
if (isset($config['pattern'])) {
if (isset($config['path'])) {
throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
}
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);
$config['path'] = $config['pattern'];
unset($config['pattern']);
}
$this->validate($config, $name, $path);
if (isset($config['resource'])) {

View File

@ -37,8 +37,7 @@
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="path" type="xsd:string" />
<xsd:attribute name="pattern" type="xsd:string" />
<xsd:attribute name="path" type="xsd:string" use="required" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="schemes" type="xsd:string" />
<xsd:attribute name="methods" type="xsd:string" />

View File

@ -91,14 +91,8 @@ class Route implements \Serializable
$this->setRequirements($requirements);
$this->setOptions($options);
$this->setHost($host);
// The conditions make sure that an initial empty $schemes/$methods does not override the corresponding requirement.
// They can be removed when the BC layer is removed.
if ($schemes) {
$this->setSchemes($schemes);
}
if ($methods) {
$this->setMethods($methods);
}
$this->setSchemes($schemes);
$this->setMethods($methods);
$this->setCondition($condition);
}
@ -142,38 +136,6 @@ class Route implements \Serializable
}
}
/**
* Returns the pattern for the path.
*
* @return string The pattern
*
* @deprecated since version 2.2, to be removed in 3.0. Use getPath instead.
*/
public function getPattern()
{
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);
return $this->path;
}
/**
* Sets the pattern for the path.
*
* This method implements a fluent interface.
*
* @param string $pattern The path pattern
*
* @return Route The current Route instance
*
* @deprecated since version 2.2, to be removed in 3.0. Use setPath instead.
*/
public function setPattern($pattern)
{
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);
return $this->setPath($pattern);
}
/**
* Returns the pattern for the path.
*
@ -254,14 +216,6 @@ class Route implements \Serializable
public function setSchemes($schemes)
{
$this->schemes = array_map('strtolower', (array) $schemes);
// this is to keep BC and will be removed in a future version
if ($this->schemes) {
$this->requirements['_scheme'] = implode('|', $this->schemes);
} else {
unset($this->requirements['_scheme']);
}
$this->compiled = null;
return $this;
@ -303,14 +257,6 @@ class Route implements \Serializable
public function setMethods($methods)
{
$this->methods = array_map('strtoupper', (array) $methods);
// this is to keep BC and will be removed in a future version
if ($this->methods) {
$this->requirements['_method'] = implode('|', $this->methods);
} else {
unset($this->requirements['_method']);
}
$this->compiled = null;
return $this;
@ -548,12 +494,6 @@ class Route implements \Serializable
*/
public function getRequirement($key)
{
if ('_scheme' === $key) {
trigger_error('The "_scheme" requirement is deprecated since version 2.2 and will be removed in 3.0. Use getSchemes() instead.', E_USER_DEPRECATED);
} elseif ('_method' === $key) {
trigger_error('The "_method" requirement is deprecated since version 2.2 and will be removed in 3.0. Use getMethods() instead.', E_USER_DEPRECATED);
}
return isset($this->requirements[$key]) ? $this->requirements[$key] : null;
}
@ -653,17 +593,6 @@ class Route implements \Serializable
throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" cannot be empty.', $key));
}
// this is to keep BC and will be removed in a future version
if ('_scheme' === $key) {
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);
$this->setSchemes(explode('|', $regex));
} elseif ('_method' === $key) {
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);
$this->setMethods(explode('|', $regex));
}
return $regex;
}
}

View File

@ -46,12 +46,4 @@ class RouteTest extends \PHPUnit_Framework_TestCase
array('condition', 'context.getMethod() == "GET"', 'getCondition'),
);
}
public function testLegacyGetPattern()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$route = new Route(array('value' => '/Blog'));
$this->assertEquals($route->getPattern(), '/Blog');
}
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog_show_legacy" pattern="/blog/{slug}" host="{locale}.example.com">
<default key="_controller">MyBundle:Blog:show</default>
<default key="slug" xsi:nil="true" />
<requirement key="_method">GET|POST|put|OpTiOnS</requirement>
<requirement key="_scheme">hTTps</requirement>
<requirement key="locale">\w+</requirement>
<option key="compiler_class">RouteCompiler</option>
<condition>context.getMethod() == "GET"</condition>
</route>
</routes>

View File

@ -1,8 +0,0 @@
blog_show_legacy:
pattern: /blog/{slug}
defaults: { _controller: "MyBundle:Blog:show" }
host: "{locale}.example.com"
requirements: { '_method': 'GET|POST|put|OpTiOnS', _scheme: https, 'locale': '\w+' }
condition: 'context.getMethod() == "GET"'
options:
compiler_class: RouteCompiler

View File

@ -45,25 +45,6 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
}
public function testLegacyRouteDefinitionLoading()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('legacy_validpattern.xml');
$route = $routeCollection->get('blog_show_legacy');
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$this->assertSame('/blog/{slug}', $route->getPath());
$this->assertSame('{locale}.example.com', $route->getHost());
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
$this->assertSame('\w+', $route->getRequirement('locale'));
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
$this->assertEquals(array('https'), $route->getSchemes());
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
}
public function testLoadWithNamespacePrefix()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));

View File

@ -79,25 +79,6 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
}
public function testLegacyRouteDefinitionLoading()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('legacy_validpattern.yml');
$route = $routeCollection->get('blog_show_legacy');
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$this->assertSame('/blog/{slug}', $route->getPath());
$this->assertSame('{locale}.example.com', $route->getHost());
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
$this->assertSame('\w+', $route->getRequirement('locale'));
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
$this->assertEquals(array('https'), $route->getSchemes());
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
}
public function testLoadWithResource()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));

View File

@ -164,23 +164,6 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($route->hasScheme('httpS'));
}
public function testLegacySchemeRequirement()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$route = new Route('/');
$route->setRequirement('_scheme', 'http|https');
$this->assertEquals('http|https', $route->getRequirement('_scheme'));
$this->assertEquals(array('http', 'https'), $route->getSchemes());
$this->assertTrue($route->hasScheme('https'));
$this->assertTrue($route->hasScheme('http'));
$this->assertFalse($route->hasScheme('ftp'));
$route->setSchemes(array('hTTp'));
$this->assertEquals('http', $route->getRequirement('_scheme'));
$route->setSchemes(array());
$this->assertNull($route->getRequirement('_scheme'));
}
public function testMethod()
{
$route = new Route('/');
@ -191,20 +174,6 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('GET', 'POST'), $route->getMethods(), '->setMethods() accepts an array of methods and uppercases them');
}
public function testLegacyMethodRequirement()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$route = new Route('/');
$route->setRequirement('_method', 'GET|POST');
$this->assertEquals('GET|POST', $route->getRequirement('_method'));
$this->assertEquals(array('GET', 'POST'), $route->getMethods());
$route->setMethods(array('gEt'));
$this->assertEquals('GET', $route->getRequirement('_method'));
$route->setMethods(array());
$this->assertNull($route->getRequirement('_method'));
}
public function testCondition()
{
$route = new Route('/');
@ -222,17 +191,6 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->assertNotSame($compiled, $route->compile(), '->compile() recompiles if the route was modified');
}
public function testLegacyPattern()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$route = new Route('/{foo}');
$this->assertEquals('/{foo}', $route->getPattern());
$route->setPattern('/bar');
$this->assertEquals('/bar', $route->getPattern());
}
public function testSerialize()
{
$route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\d+'));