diff --git a/CHANGELOG.md b/CHANGELOG.md index c8cb2a2..58beff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Changelog 3.0.0 ----- +* [BC Break] Removed deprecated VersatileRouterInterface::supports, as only string route names are + allowed since Symfony 6. +* Revoked the deprecation on Router::match because Symfony keeps offering the match without request + object. * Support Symfony 6 2.3.4 diff --git a/composer.json b/composer.json index 69da3b0..9f3de3e 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "psr/log": "^1.0 || ^2.0 || ^3.0" }, "require-dev": { + "doctrine/annotations": "^1.5", "symfony/phpunit-bridge": "^5.4 || ^6.0", "symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0", "symfony/config": "^4.4 || ^5.0 || ^6.0", diff --git a/src/ChainRouter.php b/src/ChainRouter.php index 1f9218e..c281980 100644 --- a/src/ChainRouter.php +++ b/src/ChainRouter.php @@ -230,11 +230,6 @@ public function generate($name, $parameters = [], $absolute = UrlGeneratorInterf continue; } - // If $router is versatile and doesn't support this route name, continue - if ($router instanceof VersatileGeneratorInterface && !$router->supports($name)) { - continue; - } - try { return $router->generate($name, $parameters, $absolute); } catch (RouteNotFoundException $e) { diff --git a/src/ContentAwareGenerator.php b/src/ContentAwareGenerator.php index 4e79e7f..9304359 100644 --- a/src/ContentAwareGenerator.php +++ b/src/ContentAwareGenerator.php @@ -280,16 +280,6 @@ public function setDefaultLocale($locale) $this->defaultLocale = $locale; } - /** - * We additionally support empty name and data in parameters and RouteAware content. - * - * {@inheritdoc} - */ - public function supports($name) - { - return !$name || parent::supports($name) || $name instanceof RouteReferrersReadInterface; - } - /** * {@inheritdoc} */ diff --git a/src/DynamicRouter.php b/src/DynamicRouter.php index 893401b..4c3e4d0 100644 --- a/src/DynamicRouter.php +++ b/src/DynamicRouter.php @@ -154,10 +154,8 @@ public function getGenerator() * RouteNotFoundException as documented below. * * The CMF routing system used to allow to pass route objects as $name to generate the route. - * Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract - * for BC but deprecate passing non-strings. - * Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object - * in the parameters with key RouteObjectInterface::ROUTE_OBJECT. + * To generate the route from a string, pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME + * as route name and the object in the parameters with key RouteObjectInterface::ROUTE_OBJECT. * * @param string $name The name of the route * @@ -180,20 +178,6 @@ public function generate($name, $parameters = [], $referenceType = UrlGeneratorI return $this->getGenerator()->generate($name, $parameters, $referenceType); } - /** - * Delegate to our generator. - * - * {@inheritdoc} - */ - public function supports($name) - { - if ($this->generator instanceof VersatileGeneratorInterface) { - return $this->generator->supports($name); - } - - return is_string($name); - } - /** * Tries to match a URL path with a set of routes. * @@ -209,14 +193,10 @@ public function supports($name) * @throws MethodNotAllowedException If the resource was found but the * request method is not allowed * - * @deprecated Use matchRequest exclusively to avoid problems. This method will be removed in version 2.0 - * * @api */ public function match($pathinfo): array { - @trigger_error(__METHOD__.'() is deprecated since version 1.3 and will be removed in 2.0. Use matchRequest() instead.', E_USER_DEPRECATED); - $request = Request::create($pathinfo); if ($this->eventDispatcher) { $event = new RouterMatchEvent(); diff --git a/src/ProviderBasedGenerator.php b/src/ProviderBasedGenerator.php index 409f947..fa62c30 100644 --- a/src/ProviderBasedGenerator.php +++ b/src/ProviderBasedGenerator.php @@ -69,16 +69,6 @@ public function generate($name, $parameters = [], $referenceType = self::ABSOLUT return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $debug_message, $referenceType, $hostTokens); } - /** - * Support a route object and any string as route name. - * - * {@inheritdoc} - */ - public function supports($name) - { - return is_string($name) || $name instanceof SymfonyRoute; - } - /** * {@inheritdoc} */ diff --git a/src/VersatileGeneratorInterface.php b/src/VersatileGeneratorInterface.php index 66fa368..4164d16 100644 --- a/src/VersatileGeneratorInterface.php +++ b/src/VersatileGeneratorInterface.php @@ -18,34 +18,13 @@ */ interface VersatileGeneratorInterface extends UrlGeneratorInterface { - /** - * Whether this generator supports the supplied $name. - * - * This check does not need to look if the specific instance can be - * resolved to a route, only whether the router can generate routes from - * objects of this class. - * - * @deprecated This method is deprecated since version 2.3 and will be - * removed in version 3.O. - * - * This method was used to not call generators that can not handle objects - * in $name. With Symfony 5, this becomes obsolete as the strict type - * declaration prevents passing anything else than a string as $name. - * - * @param mixed $name The route "name" which may also be an object or anything - * - * @return bool - */ - public function supports($name); - /** * Convert a route identifier (name, content object etc) into a string * usable for logging and other debug/error messages. * - * @param mixed $name In Symfony 5, the name can only be a string * @param array $parameters Which might hold a route object or content id or similar to include in the debug message * * @return string */ - public function getRouteDebugMessage($name, array $parameters = []); + public function getRouteDebugMessage(string $name, array $parameters = []); } diff --git a/tests/Unit/Routing/ChainRouterTest.php b/tests/Unit/Routing/ChainRouterTest.php index e783032..3ce6160 100644 --- a/tests/Unit/Routing/ChainRouterTest.php +++ b/tests/Unit/Routing/ChainRouterTest.php @@ -616,11 +616,6 @@ public function testGenerateWithObjectNameInParametersNotFoundVersatile() $parameters = ['test' => 'value', '_route_object' => new \stdClass()]; $chainedRouter = $this->createMock(VersatileRouter::class); - $chainedRouter - ->expects($this->once()) - ->method('supports') - ->willReturn(true) - ; $chainedRouter->expects($this->once()) ->method('generate') ->with($name, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH) @@ -726,30 +721,6 @@ public function testGenerateWithNameParameterObject() $this->router->generate(new \stdClass(), $parameters); } - /** - * @group legacy - */ - public function testSupport() - { - $router = $this->createMock(VersatileRouter::class); - $router - ->expects($this->once()) - ->method('supports') - ->will($this->returnValue(false)) - ; - - $router - ->expects($this->never()) - ->method('generate') - ->will($this->returnValue(false)) - ; - - $this->router->add($router); - - $this->expectException(RouteNotFoundException::class); - $this->router->generate('foobar'); - } - /** * @return RouterInterface[]|MockObject[] */ diff --git a/tests/Unit/Routing/ContentAwareGeneratorTest.php b/tests/Unit/Routing/ContentAwareGeneratorTest.php index b2107fa..3362701 100644 --- a/tests/Unit/Routing/ContentAwareGeneratorTest.php +++ b/tests/Unit/Routing/ContentAwareGeneratorTest.php @@ -480,17 +480,6 @@ public function testGetLocaleContext(): void $this->assertEquals('de', $this->generator->getLocale($attributes)); } - /** - * @group legacy - */ - public function testSupports(): void - { - $this->assertTrue($this->generator->supports('')); - $this->assertTrue($this->generator->supports(null)); - $this->assertTrue($this->generator->supports($this->contentDocument)); - $this->assertFalse($this->generator->supports($this)); - } - public function testGetRouteDebugMessage(): void { $this->assertStringContainsString('/some/content', $this->generator->getRouteDebugMessage(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['content_id' => '/some/content'])); @@ -498,16 +487,6 @@ public function testGetRouteDebugMessage(): void $this->assertStringContainsString('/some/content', $this->generator->getRouteDebugMessage('/some/content')); } - /** - * @legacy - */ - public function testGetRouteDebugMessageLegacy(): void - { - $this->assertStringContainsString('/some/content', $this->generator->getRouteDebugMessage(null, ['content_id' => '/some/content'])); - $this->assertStringContainsString('Route aware content Symfony\Cmf\Component\Routing\Tests\Routing\RouteAware', $this->generator->getRouteDebugMessage(new RouteAware())); - $this->assertStringContainsString('/some/content', $this->generator->getRouteDebugMessage('/some/content')); - } - public function testGenerateWithNameParameterObject(): void { $this->expectException(\InvalidArgumentException::class); diff --git a/tests/Unit/Routing/DynamicRouterTest.php b/tests/Unit/Routing/DynamicRouterTest.php index df0a250..3c60e89 100644 --- a/tests/Unit/Routing/DynamicRouterTest.php +++ b/tests/Unit/Routing/DynamicRouterTest.php @@ -138,31 +138,6 @@ public function testGenerate() $this->assertEquals('http://test', $url); } - /** - * @group legacy - */ - public function testSupports() - { - $name = 'foo/bar'; - $this->generator->expects($this->once()) - ->method('supports') - ->with($this->equalTo($name)) - ->will($this->returnValue(true)) - ; - - $this->assertTrue($this->router->supports($name)); - } - - public function testSupportsNonversatile() - { - $generator = $this->createMock(UrlGeneratorInterface::class); - $router = new DynamicRouter($this->context, $this->matcher, $generator); - $this->assertIsString($router->getRouteDebugMessage('test')); - - $this->assertTrue($router->supports('some string')); - $this->assertFalse($router->supports($this)); - } - /// match tests /// public function testGetMatcher() diff --git a/tests/Unit/Routing/ProviderBasedGeneratorTest.php b/tests/Unit/Routing/ProviderBasedGeneratorTest.php index fbaa0ac..268bd8a 100644 --- a/tests/Unit/Routing/ProviderBasedGeneratorTest.php +++ b/tests/Unit/Routing/ProviderBasedGeneratorTest.php @@ -116,13 +116,6 @@ public function testRemoveRouteObject(): void $this->assertEquals('result_url', $url); } - public function testSupports(): void - { - $this->assertTrue($this->generator->supports('foo/bar')); - $this->assertTrue($this->generator->supports($this->routeDocument)); - $this->assertFalse($this->generator->supports($this)); - } - public function testGetRouteDebugMessage(): void { $this->assertStringContainsString('/some/key', $this->generator->getRouteDebugMessage(new RouteObject()));