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

Skip to content

[Routing] remove deprecations #31792

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 1 commit into from
Jun 5, 2019
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 @@ -49,7 +49,7 @@ public function warmUp($cacheDir)
return;
}

@trigger_error(sprintf('Passing a %s without implementing %s is deprecated since Symfony 4.1.', RouterInterface::class, WarmableInterface::class), \E_USER_DEPRECATED);
throw new \LogicException(sprintf('The router %s cannot be warmed up because it does not implement %s.', \get_class($router), WarmableInterface::class));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Symfony\Bridge\Twig\Extension\CsrfExtension;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
use Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher;
use Symfony\Bundle\FullStack;
use Symfony\Component\Asset\PackageInterface;
use Symfony\Component\BrowserKit\AbstractBrowser;
Expand Down Expand Up @@ -88,12 +87,8 @@
use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
use Symfony\Component\Routing\Matcher\CompiledUrlMatcher;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
Expand Down Expand Up @@ -792,19 +787,12 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
}

$container->setParameter('router.resource', $config['resource']);
$container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.container_class')); // deprecated
$router = $container->findDefinition('router.default');
$argument = $router->getArgument(2);
$argument['strict_requirements'] = $config['strict_requirements'];
if (isset($config['type'])) {
$argument['resource_type'] = $config['type'];
}
if (!class_exists(CompiledUrlMatcher::class)) {
$argument['matcher_class'] = $argument['matcher_base_class'] = $argument['matcher_base_class'] ?? RedirectableUrlMatcher::class;
$argument['matcher_dumper_class'] = PhpMatcherDumper::class;
$argument['generator_class'] = $argument['generator_base_class'] = $argument['generator_base_class'] ?? UrlGenerator::class;
$argument['generator_dumper_class'] = PhpGeneratorDumper::class;
}
$router->replaceArgument(2, $argument);

$container->setParameter('request_listener.http_port', $config['http_port']);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ public function testWarmUpWithWarmebleInterface()
$this->addToAssertionCount(1);
}

/**
* @expectedDeprecation Passing a Symfony\Component\Routing\RouterInterface without implementing Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface is deprecated since Symfony 4.1.
* @group legacy
*/
public function testWarmUpWithoutWarmebleInterface()
{
$containerMock = $this->getMockBuilder(ContainerInterface::class)->setMethods(['get', 'has'])->getMock();

$routerMock = $this->getMockBuilder(testRouterInterfaceWithoutWarmebleInterface::class)->setMethods(['match', 'generate', 'getContext', 'setContext', 'getRouteCollection'])->getMock();
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
$routerCacheWarmer = new RouterCacheWarmer($containerMock);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('cannot be warmed up because it does not implement Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface');
$routerCacheWarmer->warmUp('/tmp');
}
}
Expand Down

This file was deleted.

8 changes: 8 additions & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

5.0.0
-----

* removed `PhpGeneratorDumper` and `PhpMatcherDumper`
* removed `generator_base_class`, `generator_cache_class`, `matcher_base_class` and `matcher_cache_class` router options
* `Serializable` implementing methods for `Route` and `CompiledRoute` are final
* removed referencing service route loaders with a single colon

4.3.0
-----

Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/Routing/CompiledRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public function __serialize(): array
}

/**
* @internal since Symfony 4.3
* @final since Symfony 4.3
* @internal
*/
public function serialize()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas removing this but keeping the new magic serialization methods means that the deserialization breaks when upgrading php to 7.4. so persisted routes will not work anymore when upgrading php. I think that was one of the main reasons why we implemented Serializable in the first place.

Copy link
Member

Choose a reason for hiding this comment

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

So, we can keep them for a smoother transition, and keep only @internal then, would that be ok to you?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, let's make them really final to close this a bit more?

Copy link
Contributor Author
@Tobion Tobion Jun 4, 2019

Choose a reason for hiding this comment

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

If we make them final Drupal can't overwrite them anymore which is what they do in https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Routing%21CompiledRoute.php/class/CompiledRoute/8.2.x
I don't see what else they could do then. It would make it impossible to adjust serialization in a subclass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikic In https://wiki.php.net/rfc/custom_object_serialization you say

For this reason, code using parent::serialize() is generally broken

But from what I see the implementation in Drupal calling parent::serialize does not seem broken

public function serialize() {
    $data = unserialize(parent::serialize());
    $data['fit'] = $this->fit;
    $data['patternOutline'] = $this->patternOutline;
    $data['numParts'] = $this->numParts;
    return serialize($data);
  }
  public function unserialize($serialized) {
    parent::unserialize($serialized);
    $data = unserialize($serialized);
    $this->fit = $data['fit'];
    $this->patternOutline = $data['patternOutline'];
    $this->numParts = $data['numParts'];
  }

It's not using backreferences but if it was, this approach using unserialize(parent::serialize() seems fine.

Copy link
Contributor Author
@Tobion Tobion Jun 4, 2019

Choose a reason for hiding this comment

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

As long as we need to support php version < 7.4, don't don't see a solution without \Serializable. So I would propose to revert #30286 for the routing component.

Copy link
Member

Choose a reason for hiding this comment

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

We provide __serialize and __unserialize as extension points. Note that yes, routes are exposed to the issue. The reason is that options/defaults can be anything, like objects with these references that break. Drupal is doing that (objects there).

This means to me we should keep implementing Serializable, but make the corresponding method @internal - and tell ppl to use __serialize and __unserialize as extension points instead.

This will provide FC/BC.

final public function serialize()
{
return serialize($this->__serialize());
}
Expand All @@ -85,10 +84,9 @@ public function __unserialize(array $data): void
}

/**
* @internal since Symfony 4.3
* @final since Symfony 4.3
* @internal
*/
public function unserialize($serialized)
final public function unserialize($serialized)
{
$this->__unserialize(unserialize($serialized, ['allowed_classes' => false]));
}
Expand Down
140 changes: 0 additions & 140 deletions src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/Symfony/Component/Routing/Loader/ObjectRouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ public function load($resource, $type = null)
throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the "service" route loader: use the format "service::method" or "service" if your service has an "__invoke" method.', $resource));
}

if (1 === substr_count($resource, ':')) {
$resource = str_replace(':', '::', $resource);
@trigger_error(sprintf('Referencing service route loaders with a single colon is deprecated since Symfony 4.1. Use %s instead.', $resource), E_USER_DEPRECATED);
}

$parts = explode('::', $resource);
$serviceString = $parts[0];
$method = $parts[1] ?? '__invoke';
Expand Down
Loading
0