Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions src/ChainRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 0 additions & 10 deletions src/ContentAwareGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
24 changes: 2 additions & 22 deletions src/DynamicRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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.
*
Expand All @@ -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();
Expand Down
10 changes: 0 additions & 10 deletions src/ProviderBasedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
23 changes: 1 addition & 22 deletions src/VersatileGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []);
}
29 changes: 0 additions & 29 deletions tests/Unit/Routing/ChainRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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[]
*/
Expand Down
21 changes: 0 additions & 21 deletions tests/Unit/Routing/ContentAwareGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,34 +480,13 @@ 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']));
$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()]));
$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);
Expand Down
25 changes: 0 additions & 25 deletions tests/Unit/Routing/DynamicRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 0 additions & 7 deletions tests/Unit/Routing/ProviderBasedGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down