Skip to content

Commit 51d756f

Browse files
committed
bug #34621 [Routing] Continue supporting single colon in object route loaders (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [Routing] Continue supporting single colon in object route loaders | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #34612 | License | MIT | Doc PR | - #32582 (comment) was a bad idea. The new `ObjectLoader` class is used directly on 4.4 since we detagged the old service (and the old one). So we need to support the old notation on it. It changes the exception message but it should be alright. Commits ------- 3c796e1 [Routing] Continue supporting single colon in object route loaders
2 parents 4633993 + 3c796e1 commit 51d756f

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

src/Symfony/Component/Routing/Loader/ObjectLoader.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ abstract protected function getObject(string $id);
4242
*/
4343
public function load($resource, $type = null)
4444
{
45-
if (!preg_match('/^[^\:]+(?:::(?:[^\:]+))?$/', $resource)) {
45+
if (!preg_match('/^[^\:]+(?:::?(?:[^\:]+))?$/', $resource)) {
4646
throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"'.$type.'"' : 'object'));
4747
}
4848

49+
if (1 === substr_count($resource, ':')) {
50+
$resource = str_replace(':', '::', $resource);
51+
@trigger_error(sprintf('Referencing object route loaders with a single colon is deprecated since Symfony 4.1. Use %s instead.', $resource), E_USER_DEPRECATED);
52+
}
53+
4954
$parts = explode('::', $resource);
5055
$method = $parts[1] ?? '__invoke';
5156

src/Symfony/Component/Routing/Loader/ObjectRouteLoader.php

-24
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Routing\Loader;
1313

14-
use Symfony\Component\Routing\RouteCollection;
15-
1614
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ObjectRouteLoader::class, ObjectLoader::class), E_USER_DEPRECATED);
1715

1816
/**
@@ -36,28 +34,6 @@ abstract class ObjectRouteLoader extends ObjectLoader
3634
*/
3735
abstract protected function getServiceObject($id);
3836

39-
/**
40-
* Calls the service that will load the routes.
41-
*
42-
* @param string $resource Some value that will resolve to a callable
43-
* @param string|null $type The resource type
44-
*
45-
* @return RouteCollection
46-
*/
47-
public function load($resource, $type = null)
48-
{
49-
if (!preg_match('/^[^\:]+(?:::?(?:[^\:]+))?$/', $resource)) {
50-
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));
51-
}
52-
53-
if (1 === substr_count($resource, ':')) {
54-
$resource = str_replace(':', '::', $resource);
55-
@trigger_error(sprintf('Referencing service route loaders with a single colon is deprecated since Symfony 4.1. Use %s instead.', $resource), E_USER_DEPRECATED);
56-
}
57-
58-
return parent::load($resource, $type);
59-
}
60-
6137
/**
6238
* {@inheritdoc}
6339
*/

src/Symfony/Component/Routing/Tests/Loader/ObjectRouteLoaderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class ObjectRouteLoaderTest extends TestCase
2323
{
2424
/**
25-
* @expectedDeprecation Referencing service route loaders with a single colon is deprecated since Symfony 4.1. Use my_route_provider_service::loadRoutes instead.
25+
* @expectedDeprecation Referencing object route loaders with a single colon is deprecated since Symfony 4.1. Use my_route_provider_service::loadRoutes instead.
2626
*/
2727
public function testLoadCallsServiceAndReturnsCollectionWithLegacyNotation()
2828
{

0 commit comments

Comments
 (0)