@@ -31,17 +31,17 @@ class AttributeBasedAutowiring implements DefinitionSource, Autowiring
3131{
3232 // Annotations configuration flags:
3333 // enable on implicit definitions
34- const IMPLICIT = 1 ;
34+ public const IMPLICIT = 1 ;
3535 // enable on all autowire definitions (which are written in DI config) by default
36- const EXPLICIT = 2 ;
36+ public const EXPLICIT = 2 ;
3737 // read @Injectable annotations for classes
38- const INJECTABLE = 4 ;
38+ public const INJECTABLE = 4 ;
3939 // read @Inject annotations for properties
40- const PROPERTIES = 8 ;
40+ public const PROPERTIES = 8 ;
4141 // read @Inject annotations for methods' parameters
42- const METHODS = 16 ;
42+ public const METHODS = 16 ;
4343 // all options enabled
44- const ALL = 31 ;
44+ public const ALL = 31 ;
4545
4646 public function __construct (private int $ flags = 0 )
4747 {
@@ -57,17 +57,17 @@ public function autowire(string $name, ObjectDefinition $definition = null) : Ob
5757 }
5858
5959 $ definition = $ definition ?: new ObjectDefinition ($ name );
60- $ useAnnotations = $ definition instanceof AutowireDefinition
61- ? ($ definition ->isUsingAnnotations () ?? ($ this ->flags & self ::EXPLICIT ))
62- : ($ this ->flags & self ::IMPLICIT );
60+ $ useAttributes = $ definition instanceof AutowireDefinition
61+ ? ($ definition ->isUsingAttributes () ?? ( bool ) ($ this ->flags & self ::EXPLICIT ))
62+ : (bool ) ( $ this ->flags & self ::IMPLICIT );
6363
6464 $ class = null ;
65- if ($ useAnnotations && $ this ->flags >= self ::INJECTABLE ) {
65+ if ($ useAttributes && $ this ->flags >= self ::INJECTABLE ) {
6666 $ class = new ReflectionClass ($ className );
6767
68- $ this ->readInjectableAttribute ($ class , $ definition );
68+ $ this ->readInjectableAttribute ($ class , $ definition );
6969 if ($ this ->flags & self ::INJECTABLE ) {
70- $ this ->readInjectableAnnotation ($ class , $ definition );
70+ $ this ->readInjectableAttribute ($ class , $ definition );
7171 }
7272
7373 // Browse the class properties looking for annotated properties
@@ -83,8 +83,8 @@ public function autowire(string $name, ObjectDefinition $definition = null) : Ob
8383
8484 // constructor parameters should always be read, even if annotations are disabled (completely or i.a. for methods)
8585 // so that it behaves at least as ReflectionBasedAutowiring
86- if (!$ useAnnotations || !($ this ->flags & self ::METHODS )) {
87- $ class = $ class ?? new ReflectionClass ($ className );
86+ if (!$ useAttributes || !($ this ->flags & self ::METHODS )) {
87+ $ class ??= new ReflectionClass ($ className );
8888 $ this ->readConstructor ($ class , $ definition );
8989 }
9090
@@ -109,7 +109,7 @@ public function getDefinitions() : array
109109 }
110110
111111 /**
112- * Browse the class properties looking for annotated properties.
112+ * Browse the class properties looking for properties with attributes .
113113 */
114114 private function readProperties (ReflectionClass $ class , ObjectDefinition $ definition ) : void
115115 {
@@ -182,7 +182,7 @@ private function readProperty(ReflectionProperty $property, ObjectDefinition $de
182182 }
183183
184184 /**
185- * Browse the object's methods looking for annotated methods.
185+ * Browse the object's methods looking for methods with attributes .
186186 */
187187 private function readMethods (ReflectionClass $ class , ObjectDefinition $ objectDefinition ) : void
188188 {
@@ -214,17 +214,17 @@ private function getMethodInjection(ReflectionMethod $method) : ?MethodInjection
214214 if ($ attribute ) {
215215 /** @var Inject $inject */
216216 $ inject = $ attribute ->newInstance ();
217- $ annotationParameters = $ inject ->getParameters ();
217+ $ attributeParameters = $ inject ->getParameters ();
218218 } elseif ($ method ->isConstructor ()) {
219219 // #[Inject] on constructor is implicit, we continue
220- $ annotationParameters = [];
220+ $ attributeParameters = [];
221221 } else {
222222 return null ;
223223 }
224224
225225 $ parameters = [];
226226 foreach ($ method ->getParameters () as $ index => $ parameter ) {
227- $ entryName = $ this ->getMethodParameter ($ index , $ parameter , $ annotationParameters );
227+ $ entryName = $ this ->getMethodParameter ($ index , $ parameter , $ attributeParameters );
228228
229229 if ($ entryName !== null ) {
230230 $ parameters [$ index ] = new Reference ($ entryName );
@@ -241,7 +241,7 @@ private function getMethodInjection(ReflectionMethod $method) : ?MethodInjection
241241 /**
242242 * @return string|null Entry name or null if not found.
243243 */
244- private function getMethodParameter (int $ parameterIndex , ReflectionParameter $ parameter , array $ annotationParameters ) : ?string
244+ private function getMethodParameter (int $ parameterIndex , ReflectionParameter $ parameter , array $ attributeParameters ) : ?string
245245 {
246246 // Let's check if this parameter has an #[Inject] attribute
247247 $ attribute = $ parameter ->getAttributes (Inject::class)[0 ] ?? null ;
@@ -253,11 +253,11 @@ private function getMethodParameter(int $parameterIndex, ReflectionParameter $pa
253253 }
254254
255255 // #[Inject] has definition for this parameter (by index, or by name)
256- if (isset ($ annotationParameters [$ parameterIndex ])) {
257- return $ annotationParameters [$ parameterIndex ];
256+ if (isset ($ attributeParameters [$ parameterIndex ])) {
257+ return $ attributeParameters [$ parameterIndex ];
258258 }
259- if (isset ($ annotationParameters [$ parameter ->getName ()])) {
260- return $ annotationParameters [$ parameter ->getName ()];
259+ if (isset ($ attributeParameters [$ parameter ->getName ()])) {
260+ return $ attributeParameters [$ parameter ->getName ()];
261261 }
262262
263263 // Skip optional parameters if not explicitly defined
0 commit comments