From 93e5f43f9c50dd1752ee51606508505fa84a0a7a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 6 Apr 2024 21:02:45 +0200 Subject: [PATCH] annotations @inject is deprecated (BC break) --- src/DI/Helpers.php | 3 +++ tests/DI/Container.inject.properties.phpt | 7 +++--- tests/DI/Helpers.parseAnnotation().phpt | 22 ++++++++----------- tests/DI/InjectExtension.basic.phpt | 7 +++--- tests/DI/InjectExtension.errors.phpt | 11 +++++----- ...InjectExtension.getInjectProperties().phpt | 6 ++--- ...xtension.getInjectProperties().traits.phpt | 3 ++- 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/DI/Helpers.php b/src/DI/Helpers.php index 3597a3820..16d6b44ba 100644 --- a/src/DI/Helpers.php +++ b/src/DI/Helpers.php @@ -202,6 +202,7 @@ public static function prefixServiceName(mixed $config, string $namespace): mixe /** * Returns an annotation value. + * @deprecated */ public static function parseAnnotation(\Reflector $ref, string $name): ?string { @@ -211,6 +212,8 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?string $re = '#[\s*]@' . preg_quote($name, '#') . '(?=\s|$)(?:[ \t]+([^@\s]\S*))?#'; if ($ref->getDocComment() && preg_match($re, trim($ref->getDocComment(), '/*'), $m)) { + $alt = $name === 'inject' ? '#[Nette\DI\Attributes\Inject]' : 'alternative'; + trigger_error("Annotation @$name is deprecated, use $alt (used in " . Reflection::toString($ref) . ')', E_USER_DEPRECATED); return $m[1] ?? ''; } diff --git a/tests/DI/Container.inject.properties.phpt b/tests/DI/Container.inject.properties.phpt index 8b0203539..73324665c 100644 --- a/tests/DI/Container.inject.properties.phpt +++ b/tests/DI/Container.inject.properties.phpt @@ -7,6 +7,7 @@ declare(strict_types=1); use Nette\DI; +use Nette\DI\Attributes\Inject; use Tester\Assert; @@ -23,16 +24,16 @@ class Foo implements IFoo class Test1 { - /** @inject */ + #[Inject] public stdClass $varA; } class Test2 extends Test1 { - /** @inject */ + #[Inject] public stdClass $varC; - /** @inject */ + #[Inject] public IFoo $varD; } diff --git a/tests/DI/Helpers.parseAnnotation().phpt b/tests/DI/Helpers.parseAnnotation().phpt index 3406024bd..44115be43 100644 --- a/tests/DI/Helpers.parseAnnotation().phpt +++ b/tests/DI/Helpers.parseAnnotation().phpt @@ -1,9 +1,5 @@