8000 feature #22384 [DI] Replace autowiring BC break by regular deprecatio… · symfony/symfony@0c19ca8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c19ca8

Browse files
committed
feature #22384 [DI] Replace autowiring BC break by regular deprecation (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Replace autowiring BC break by regular deprecation | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - It happens that doing so is really easy now. And as discussed in #22295, this should be more friendly to our users. Commits ------- 0ed087d [DI] Replace autowiring BC break by regular deprecation
2 parents 2f885cc + 0ed087d commit 0c19ca8

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

UPGRADE-3.3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Debug
8080
DependencyInjection
8181
-------------------
8282

83-
* [BC BREAK] autowiring now happens only when a type-hint matches its corresponding FQCN id or alias. Please follow the suggestions provided by the exceptions thrown at compilation to upgrade your service configuration.
83+
* Autowiring services based on the types they implement is deprecated and won't be supported in version 4.0. Rename (or alias) your services to their FQCN id to make them autowirable.
8484

8585
* [BC BREAK] `_defaults` and `_instanceof` are now reserved service names in Yaml configurations. Please rename any services with that names.
8686

UPGRADE-4.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Debug
7373
DependencyInjection
7474
-------------------
7575

76-
* Autowiring now happens only when a type-hint matches its corresponding FQCN id or alias.
76+
* Autowiring services based on the types they implement is not supported anymore. Rename (or alias) your services to their FQCN id to make them autowirable.
7777

7878
* `_defaults` and `_instanceof` are now reserved service names in Yaml configurations. Please rename any services with that names.
7979

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ CHANGELOG
44
3.3.0
55
-----
66

7-
* [BC BREAK] autowiring now happens only when a type-hint matches its corresponding FQCN id or alias.
8-
Please follow the suggestions provided by the exceptions thrown at compilation to upgrade your service configuration.
7+
* deprecated autowiring services based on the types they implement;
8+
rename (or alias) your services to their FQCN id to make them autowirable
99
* added "ServiceSubscriberInterface" - to allow for per-class explicit service-locator definitions
1010
* added "container.service_locator" tag for defining service-locator services
1111
* added anonymous services support in YAML configuration files using the `!service` tag.

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ private function getAutowiredReference(TypedReference $reference)
291291
return new TypedReference($this->types[$type], $type);
292292
}
293293

294+
if (isset($this->types[$type])) {
295+
@trigger_error(sprintf('Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0. You should %s the "%s" service to "%s" instead.', isset($this->types[$this->types[$type]]) ? 'alias' : 'rename (or alias)', $this->types[$type], $type), E_USER_DEPRECATED);
296+
297+
return new TypedReference($this->types[$type], $type);
298+
}
299+
294300
if (!$reference->canBeAutoregistered() || isset($this->types[$type]) || isset($this->ambiguousServiceTypes[$type])) {
295301
return;
296302
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ public function testProcessVariadic()
5858
}
5959

6060
/**
61-
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
62-
* @expectedExceptionMessage Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.
61+
* @group legacy
62+
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\B" service to "Symfony\Component\DependencyInjection\Tests\Compiler\A" instead.
63+
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
64+
* @expectedExceptionMessageInSymfony4 Cannot autowire service "c": argument "$a" of method "Symfony\Component\DependencyInjection\Tests\Compiler\C::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\B" service.
6365
*/
6466
public function testProcessAutowireParent()
6567
{
@@ -77,8 +79,10 @@ public function testProcessAutowireParent()
7779
}
7880

7981
/**
80-
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
81-
* @expectedExceptionMessage Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service.
82+
* @group legacy
83+
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "Symfony\Component\DependencyInjection\Tests\Compiler\F" service to "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" instead.
84+
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
85+
* @expectedExceptionMessageInSymfony4 Cannot autowire service "g": argument "$d" of method "Symfony\Component\DependencyInjection\Tests\Compiler\G::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\DInterface" but no such service exists. You should maybe alias this interface to the existing "Symfony\Component\DependencyInjection\Tests\Compiler\F" service.
8286
*/
8387
public function testProcessAutowireInterface()
8488
{
@@ -333,8 +337,10 @@ public function testParentClassNotFoundThrowsException()
333337
}
334338

335339
/**
336-
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
337-
* @expectedExceptionMessage Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service.
340+
* @group legacy
341+
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead.
342+
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
343+
* @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but this service is abstract. You should maybe alias this class to the existing "foo" service.
338344
*/
339345
public function testDontUseAbstractServices()
340346
{
@@ -603,8 +609,10 @@ public function testSetterInjectionCollisionThrowsException()
603609
}
604610

605611
/**
606-
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
607-
* @expectedExceptionMessage Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service.
612+
* @group legacy
613+
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "foo" service to "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" instead.
614+
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
615+
* @expectedExceptionMessageInSymfony4 Cannot autowire service "bar": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\Bar::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to the existing "foo" service.
608616
*/
609617
public function testProcessDoesNotTriggerDeprecations()
610618
{
@@ -691,8 +699,10 @@ public function provideNotWireableCalls()
691699
}
692700

693701
/**
694-
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
695-
* @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to the existing "i" service; or type-hint against interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
702+
* @group legacy
703+
* @expectedDeprecation Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "i" service to "Symfony\Component\DependencyInjection\Tests\Compiler\I" instead.
704+
* @expectedExceptionInSymfony4 \Symfony\Component\DependencyInjection\Exception\RuntimeException
705+
* @expectedExceptionMessageInSymfony4 Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to the existing "i" service; or type-hint against interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
696706
*/
697707
public function testByIdAlternative()
698708
{

0 commit comments

Comments
 (0)
0