@@ -121,21 +121,6 @@ public function process(ContainerBuilder $container)
121
121
$ args = [];
122
122
foreach ($ parameters as $ p ) {
123
123
/** @var \ReflectionParameter $p */
124
- if (class_exists (Autowire::class) && $ attr = $ p ->getAttributes (Autowire::class)[0 ] ?? null ) {
125
- $ value = $ attr ->newInstance ()->value ;
126
-
127
- if ($ value instanceof Reference) {
128
- $ args [$ p ->name ] = new Reference ($ value , $ p ->allowsNull () ? ContainerInterface::NULL_ON_INVALID_REFERENCE : ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE );
129
- } else {
130
- $ args [$ p ->name ] = new Reference ('.value. ' .$ container ->hash ($ value ));
131
- $ container ->register ((string ) $ args [$ p ->name ], 'mixed ' )
132
- ->setFactory ('current ' )
133
- ->addArgument ([$ value ]);
134
- }
135
-
136
- continue ;
137
- }
138
-
139
124
$ type = ltrim ($ target = (string ) ProxyHelper::getTypeHint ($ r , $ p ), '\\' );
140
125
$ invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE ;
141
126
@@ -164,7 +149,7 @@ public function process(ContainerBuilder $container)
164
149
}
165
150
166
151
continue ;
167
- } elseif (!$ type || ! $ autowire || '\\' !== $ target [0 ]) {
152
+ } elseif (!$ autowire || (! $ p -> getAttributes (Autowire::class) && (! $ type || '\\' !== $ target [0 ])) ) {
168
153
continue ;
169
154
} elseif (is_subclass_of ($ type , \UnitEnum::class)) {
170
155
// do not attempt to register enum typed arguments if not already present in bindings
@@ -177,6 +162,21 @@ public function process(ContainerBuilder $container)
177
162
continue ;
178
163
}
179
164
165
+ if (class_exists (Autowire::class) && $ attr = $ p ->getAttributes (Autowire::class)[0 ] ?? null ) {
166
+ $ value = $ attr ->newInstance ()->value ;
167
+
168
+ if ($ value instanceof Reference) {
169
+ $ args [$ p ->name ] = $ type ? new TypedReference ($ value , $ type , $ invalidBehavior , $ p ->name ) : new Reference ($ value , $ invalidBehavior );
170
+ } else {
171
+ $ args [$ p ->name ] = new Reference ('.value. ' .$ container ->hash ($ value ));
172
+ $ container ->register ((string ) $ args [$ p ->name ], 'mixed ' )
173
+ ->setFactory ('current ' )
174
+ ->addArgument ([$ value ]);
175
+ }
176
+
177
+ continue ;
178
+ }
179
+
180
180
if ($ type && !$ p ->isOptional () && !$ p ->allowsNull () && !class_exists ($ type ) && !interface_exists ($ type , false )) {
181
181
$ message = sprintf ('Cannot determine controller argument for "%s::%s()": the $%s argument is type-hinted with the non-existent class or interface: "%s". ' , $ class , $ r ->name , $ p ->name , $ type );
182
182
0 commit comments