diff --git a/src/DI/Helpers.php b/src/DI/Helpers.php index 6d782426c..bbf1a04f0 100644 --- a/src/DI/Helpers.php +++ b/src/DI/Helpers.php @@ -210,6 +210,7 @@ public static function prefixServiceName(mixed $config, string $namespace): mixe /** * Returns an annotation value. + * @deprecated */ public static function parseAnnotation(\Reflector $ref, string $name): ?string { @@ -219,6 +220,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 @@