8000 6.3 deprecate the "@required" annotation · symfony/symfony@dcf42d3 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dcf42d3

Browse files
6.3 deprecate the "@required" annotation
1 parent 1f7bc10 commit dcf42d3

File tree

8 files changed

+29
-0
lines changed

8 files changed

+29
-0
lines changed

UPGRADE-7.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
UPGRADE FROM 6.4 to 7.0
22
=======================
33 8000

4+
DependencyInjection
5+
-------------------
6+
7+
* Remove the `@required` annotation in favor of the
8+
`Symfony\Contracts\Service\Attribute\Required` attribute
9+
410
Messenger
511
---------
612

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
* Deprecate `framework:exceptions` tag, unwrap it and replace `framework:exception` tags' `name` attribute by `class`
1313
* Deprecate the `notifier.logger_notification_listener` service, use the `notifier.notification_logger_listener` service instead
1414
* Allow setting private services with the test container
15+
* Deprecate the `@required` annotation, use the attribute `Symfony\Contracts\Service\Attribute\Required` instead
1516

1617
6.2
1718
---

src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
return static function (ContainerConfigurator $container) {
2323
$container->services()
24+
// remove this in Symfony 7.0, the "@required" annotation will be removed
2425
->set('annotations.reader', AnnotationReader::class)
2526
->call('addGlobalIgnoredName', ['required'])
2627

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Deprecate undefined and numeric keys with `service_locator` config
1212
* Fail if Target attribute does not exist during compilation
1313
* Enable deprecating parameters with `ContainerBuilder::deprecateParameter()`
14+
* Deprecate the `@required` annotation, use the attribute `Symfony\Contracts\Service\Attribute\Required` instead
1415

1516
6.2
1617
---

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
5656
break;
5757
}
5858
if (false !== $doc = $r->getDocComment()) {
59+
// remove this in Symfony 7.0, the "@required" annotation will be removed
5960
if (false !== stripos($doc, '@required') && preg_match('#(?:^/\*\*|\n\s*+\*)\s*+@required(?:\s|\*/$)#i', $doc)) {
61+
trigger_deprecation('symfony/dependency-injection', '6.3', 'The "@required" annotation is deprecated, use the attribute "Symfony\Contracts\Service\Attribute\Required" instead.');
62+
6063
if ($this->isWither($reflectionMethod, $doc)) {
6164
$withers[] = [$reflectionMethod->name, [], true];
6265
} else {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
4545
) {
4646
continue;
4747
}
48+
trigger_deprecation('symfony/dependency-injection', '6.3', 'The "@required" annotation is deprecated, use the attribute "Symfony\Contracts\Service\Attribute\Required" instead.');
4849
if (\array_key_exists($name = $reflectionProperty->getName(), $properties)) {
4950
continue;
5051
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psr\Log\LoggerInterface;
1616
use Psr\Log\NullLogger;
1717
use Symfony\Bridge\PhpUnit\ClassExistsMock;
18+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1819
use Symfony\Component\Config\FileLocator;
1920
use Symfony\Component\Config\Resource\ClassExistenceResource;
2021
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
@@ -41,6 +42,8 @@
4142

4243
class AutowirePassTest extends TestCase
4344
{
45+
use ExpectDeprecationTrait;
46+
4447
public static function setUpBeforeClass(): void
4548
{
4649
ClassExistsMock::register(AutowirePass::class);
@@ -766,8 +769,13 @@ public function testWithNonExistingSetterAndAutowiring()
766769
(new AutowirePass())->process($container);
767770
}
768771

772+
/**
773+
* @group legacy
774+
*/
769775
public function testExplicitMethodInjection()
770776
{
777+
$this->expectDeprecation('Since symfony/dependency-injection 6.3: The "@required" annotation will be removed. Use the attribute "Symfony\Contracts\Service\Attribute\Required" instead.');
778+
771779
$container = new ContainerBuilder();
772780
$container->register(Foo::class);
773781
$container->register(A::class);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
1617
use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -21,6 +22,8 @@
2122

2223
class AutowireRequiredMethodsPassTest extends TestCase
2324
{
25+
use ExpectDeprecationTrait;
26+
2427
public function testSetterInjection()
2528
{
2629
$container = new ContainerBuilder();
@@ -70,8 +73,13 @@ public function testSetterInjectionWithAttribute()
7073
$this->assertSame([['setFoo', []]], $methodCalls);
7174
}
7275

76+
/**
77+
* @group legacy
78+
*/
7379
public function testExplicitMethodInjection()
7480
{
81+
$this->expectDeprecation('Since symfony/dependency-injection 6.3: The "@required" annotation will be removed. Use the attribute "Symfony\Contracts\Service\Attribute\Required" instead.');
82+
7583
$container = new ContainerBuilder();
7684
$container->register(Foo::class);
7785
$container->register(A::class);

0 commit comments

Comments
 (0)
0