Skip to content

Commit cc05a17

Browse files
authored
Merge pull request #272 from symfony-cmf/drop-deprecated
remove deprecated things.
2 parents cd882f0 + cf92e4e commit cc05a17

11 files changed

+8
-151
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Changelog
44
3.0.0
55
-----
66

7+
* [BC Break] Removed deprecated VersatileRouterInterface::supports, as only string route names are
8+
allowed since Symfony 6.
9+
* Revoked the deprecation on Router::match because Symfony keeps offering the match without request
10+
object.
711
* Support Symfony 6
812

913
2.3.4

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"psr/log": "^1.0 || ^2.0 || ^3.0"
2222
},
2323
"require-dev": {
24+
"doctrine/annotations": "^1.5",
2425
"symfony/phpunit-bridge": "^5.4 || ^6.0",
2526
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
2627
"symfony/config": "^4.4 || ^5.0 || ^6.0",

src/ChainRouter.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,6 @@ public function generate($name, $parameters = [], $absolute = UrlGeneratorInterf
230230
continue;
231231
}
232232

233-
// If $router is versatile and doesn't support this route name, continue
234-
if ($router instanceof VersatileGeneratorInterface && !$router->supports($name)) {
235-
continue;
236-
}
237-
238233
try {
239234
return $router->generate($name, $parameters, $absolute);
240235
} catch (RouteNotFoundException $e) {

src/ContentAwareGenerator.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,6 @@ public function setDefaultLocale($locale)
280280
$this->defaultLocale = $locale;
281281
}
282282

283-
/**
284-
* We additionally support empty name and data in parameters and RouteAware content.
285-
*
286-
* {@inheritdoc}
287-
*/
288-
public function supports($name)
289-
{
290-
return !$name || parent::supports($name) || $name instanceof RouteReferrersReadInterface;
291-
}
292-
293283
/**
294284
* {@inheritdoc}
295285
*/

src/DynamicRouter.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,8 @@ public function getGenerator()
154154
* RouteNotFoundException as documented below.
155155
*
156156
* The CMF routing system used to allow to pass route objects as $name to generate the route.
157-
* Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract
158-
* for BC but deprecate passing non-strings.
159-
* Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
160-
* in the parameters with key RouteObjectInterface::ROUTE_OBJECT.
157+
* To generate the route from a string, pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME
158+
* as route name and the object in the parameters with key RouteObjectInterface::ROUTE_OBJECT.
161159
*
162160
* @param string $name The name of the route
163161
*
@@ -180,20 +178,6 @@ public function generate($name, $parameters = [], $referenceType = UrlGeneratorI
180178
return $this->getGenerator()->generate($name, $parameters, $referenceType);
181179
}
182180

183-
/**
184-
* Delegate to our generator.
185-
*
186-
* {@inheritdoc}
187-
*/
188-
public function supports($name)
189-
{
190-
if ($this->generator instanceof VersatileGeneratorInterface) {
191-
return $this->generator->supports($name);
192-
}
193-
194-
return is_string($name);
195-
}
196-
197181
/**
198182
* Tries to match a URL path with a set of routes.
199183
*
@@ -209,14 +193,10 @@ public function supports($name)
209193
* @throws MethodNotAllowedException If the resource was found but the
210194
* request method is not allowed
211195
*
212-
* @deprecated Use matchRequest exclusively to avoid problems. This method will be removed in version 2.0
213-
*
214196
* @api
215197
*/
216198
public function match($pathinfo): array
217199
{
218-
@trigger_error(__METHOD__.'() is deprecated since version 1.3 and will be removed in 2.0. Use matchRequest() instead.', E_USER_DEPRECATED);
219-
220200
$request = Request::create($pathinfo);
221201
if ($this->eventDispatcher) {
222202
$event = new RouterMatchEvent();

src/ProviderBasedGenerator.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,6 @@ public function generate($name, $parameters = [], $referenceType = self::ABSOLUT
6969
return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $debug_message, $referenceType, $hostTokens);
7070
}
7171

72-
/**
73-
* Support a route object and any string as route name.
74-
*
75-
* {@inheritdoc}
76-
*/
77-
public function supports($name)
78-
{
79-
return is_string($name) || $name instanceof SymfonyRoute;
80-
}
81-
8272
/**
8373
* {@inheritdoc}
8474
*/

src/VersatileGeneratorInterface.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,13 @@
1818
*/
1919
interface VersatileGeneratorInterface extends UrlGeneratorInterface
2020
{
21-
/**
22-
* Whether this generator supports the supplied $name.
23-
*
24-
* This check does not need to look if the specific instance can be
25-
* resolved to a route, only whether the router can generate routes from
26-
* objects of this class.
27-
*
28-
* @deprecated This method is deprecated since version 2.3 and will be
29-
* removed in version 3.O.
30-
*
31-
* This method was used to not call generators that can not handle objects
32-
* in $name. With Symfony 5, this becomes obsolete as the strict type
33-
* declaration prevents passing anything else than a string as $name.
34-
*
35-
* @param mixed $name The route "name" which may also be an object or anything
36-
*
37-
* @return bool
38-
*/
39-
public function supports($name);
40-
4121
/**
4222
* Convert a route identifier (name, content object etc) into a string
4323
* usable for logging and other debug/error messages.
4424
*
45-
* @param mixed $name In Symfony 5, the name can only be a string
4625
* @param array $parameters Which might hold a route object or content id or similar to include in the debug message
4726
*
4827
* @return string
4928
*/
50-
public function getRouteDebugMessage($name, array $parameters = []);
29+
public function getRouteDebugMessage(string $name, array $parameters = []);
5130
}

tests/Unit/Routing/ChainRouterTest.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,6 @@ public function testGenerateWithObjectNameInParametersNotFoundVersatile()
616616
$parameters = ['test' => 'value', '_route_object' => new \stdClass()];
617617

618618
$chainedRouter = $this->createMock(VersatileRouter::class);
619-
$chainedRouter
620-
->expects($this->once())
621-
->method('supports')
622-
->willReturn(true)
623-
;
624619
$chainedRouter->expects($this->once())
625620
->method('generate')
626621
->with($name, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH)
@@ -726,30 +721,6 @@ public function testGenerateWithNameParameterObject()
726721
$this->router->generate(new \stdClass(), $parameters);
727722
}
728723

729-
/**
730-
* @group legacy
731-
*/
732-
public function testSupport()
733-
{
734-
$router = $this->createMock(VersatileRouter::class);
735-
$router
736-
->expects($this->once())
737-
->method('supports')
738-
->will($this->returnValue(false))
739-
;
740-
741-
$router
742-
->expects($this->never())
743-
->method('generate')
744-
->will($this->returnValue(false))
745-
;
746-
747-
$this->router->add($router);
748-
749-
$this->expectException(RouteNotFoundException::class);
750-
$this->router->generate('foobar');
751-
}
752-
753724
/**
754725
* @return RouterInterface[]|MockObject[]
755726
*/

tests/Unit/Routing/ContentAwareGeneratorTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -480,34 +480,13 @@ public function testGetLocaleContext(): void
480480
$this->assertEquals('de', $this->generator->getLocale($attributes));
481481
}
482482

483-
/**
484-
* @group legacy
485-
*/
486-
public function testSupports(): void
487-
{
488-
$this->assertTrue($this->generator->supports(''));
489-
$this->assertTrue($this->generator->supports(null));
490-
$this->assertTrue($this->generator->supports($this->contentDocument));
491-
$this->assertFalse($this->generator->supports($this));
492-
}
493-
494483
public function testGetRouteDebugMessage(): void
495484
{
496485
$this->assertStringContainsString('/some/content', $this->generator->getRouteDebugMessage(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, ['content_id' => '/some/content']));
497486
$this->assertStringContainsString('Route aware content Symfony\Cmf\Component\Routing\Tests\Routing\RouteAware', $this->generator->getRouteDebugMessage(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [RouteObjectInterface::ROUTE_OBJECT => new RouteAware()]));
498487
$this->assertStringContainsString('/some/content', $this->generator->getRouteDebugMessage('/some/content'));
499488
}
500489

501-
/**
502-
* @legacy
503-
*/
504-
public function testGetRouteDebugMessageLegacy(): void
505-
{
506-
$this->assertStringContainsString('/some/content', $this->generator->getRouteDebugMessage(null, ['content_id' => '/some/content']));
507-
$this->assertStringContainsString('Route aware content Symfony\Cmf\Component\Routing\Tests\Routing\RouteAware', $this->generator->getRouteDebugMessage(new RouteAware()));
508-
$this->assertStringContainsString('/some/content', $this->generator->getRouteDebugMessage('/some/content'));
509-
}
510-
511490
public function testGenerateWithNameParameterObject(): void
512491
{
513492
$this->expectException(\InvalidArgumentException::class);

tests/Unit/Routing/DynamicRouterTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -138,31 +138,6 @@ public function testGenerate()
138138
$this->assertEquals('http://test', $url);
139139
}
140140

141-
/**
142-
* @group legacy
143-
*/
144-
public function testSupports()
145-
{
146-
$name = 'foo/bar';
147-
$this->generator->expects($this->once())
148-
->method('supports')
149-
->with($this->equalTo($name))
150-
->will($this->returnValue(true))
151-
;
152-
153-
$this->assertTrue($this->router->supports($name));
154-
}
155-
156-
public function testSupportsNonversatile()
157-
{
158-
$generator = $this->createMock(UrlGeneratorInterface::class);
159-
$router = new DynamicRouter($this->context, $this->matcher, $generator);
160-
$this->assertIsString($router->getRouteDebugMessage('test'));
161-
162-
$this->assertTrue($router->supports('some string'));
163-
$this->assertFalse($router->supports($this));
164-
}
165-
166141
/// match tests ///
167142

168143
public function testGetMatcher()

0 commit comments

Comments
 (0)