8000 [Routing] remove deprecations for 3.0 by Tobion · Pull Request #13396 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] remove deprecations for 3.0 #13396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ private function writeData(array $data, array $options)
*/
protected function getRouteData(Route $route)
{
$requirements = $route->getRequirements();
unset($requirements['_scheme'], $requirements['_method']);

return array(
'path' => $route->getPath(),
'pathRegex' => $route->compile()->getRegex(),
Expand All @@ -192,7 +189,7 @@ protected function getRouteData(Route $route)
'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(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio
*/
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')
Expand All @@ -60,7 +57,7 @@ protected function describeRoute(Route $route, array $options = array())
."\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'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio
*/
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(),
Expand All @@ -83,7 +80,7 @@ protected function describeRoute(Route $route, array $options = array())
'<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()),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ private function getRouteDocument(Route $route, $name = null)
}
}

$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));
Expand Down
4 changes: 0 additions & 4 deletions src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ private function resolveParameters(RouteCollection $collection)
}

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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be the first where this would be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only required for tests not the actual functionality (because _scheme/_method would not hurt). Is it possible to have the same dependecy with different versions for require and require-dev?
I.e. ~2.7|~3.0 in require but ~3.0 in require-dev?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's not unfortunately. You should adjust the tests to make them less strict. With assertStringMatchesFormat it should be possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we just leave it this way. Sooner or later its gonna happen anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it required for tests of the FrameworkBundle ? Which test is actually breaking when running it on Routing 2.7 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the one describing routes in the console in xml, yaml etc format

"symfony/security-core": "~2.7|~3.0",
"symfony/security-csrf": "~2.7|~3.0",
"symfony/stopwatch": "~2.7|~3.0",
Expand Down
20 changes: 0 additions & 20 deletions src/Symfony/Component/Routing/Annotation/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,6 @@ public function __construct(array $data)
}
}

/**
* @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;
Expand Down
4 changes: 0 additions & 4 deletions src/Symfony/Component/Routing/Generator/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,6 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,8 @@ protected function getGlobals(\ReflectionClass $class)
);

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()) {
Expand Down
13 changes: 1 addition & 12 deletions src/Symfony/Component/Routing/Loader/XmlFileLoader.php
F987
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,10 @@ public function supports($resource, $type = null)
*/
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);

Expand Down
13 changes: 1 addition & 12 deletions src/Symfony/Component/Routing/Loader/YamlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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;

Expand Down Expand Up @@ -76,17 +76,6 @@ public function load($file, $type = null)
}

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'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
75 changes: 2 additions & 73 deletions src/Symfony/Component/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,8 @@ public function __construct($path, array $defaults = array(), array $requirement
$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);
}

Expand Down Expand Up @@ -142,38 +136,6 @@ public function unserialize($serialized)
}
}

/**
* 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.
*
Expand Down Expand Up @@ -254,14 +216,6 @@ public function getSchemes()
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;
Expand Down Expand Up @@ -303,14 +257,6 @@ public function getMethods()
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;
Expand Down Expand Up @@ -548,12 +494,6 @@ public function addRequirements(array $requirements)
*/
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;
}

Expand Down Expand Up @@ -653,17 +593,6 @@ private function sanitizeRequirement($key, $regex)
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;
}
}
8 changes: 0 additions & 8 deletions src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,4 @@ public function getValidParameters()
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');
}
}

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ public function testLoadWithRoute()
$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')));
Expand Down
Loading
0