55namespace Respect \Config ;
66
77use Psr \Container \ContainerInterface ;
8- use ReflectionNamedType ;
9-
10- use function array_key_exists ;
8+ use Respect \Parameter \Resolver ;
119
1210class Autowire extends Instantiator
1311{
@@ -24,28 +22,16 @@ protected function cleanupParams(array $params, bool $forConstructor = true): ar
2422 $ constructor = $ this ->reflection ()->getConstructor ();
2523 $ container = $ this ->container ;
2624 if ($ forConstructor && $ constructor && $ container ) {
27- foreach ($ constructor ->getParameters () as $ param ) {
28- $ name = $ param ->getName ();
29- if (array_key_exists ($ name , $ this ->params )) {
30- $ value = $ params [$ name ] ?? null ;
31- if ($ value instanceof Ref) {
32- $ params [$ name ] = $ container ->get ($ value ->id );
33- } else {
34- $ this ->propagateContainer ($ value );
35- $ params [$ name ] = $ this ->lazyLoad ($ value );
36- }
25+ foreach ($ params as $ name => $ value ) {
26+ if ($ value instanceof Ref) {
27+ $ params [$ name ] = $ container ->get ($ value ->id );
3728 } else {
38- $ type = $ param ->getType ();
39- if (
40- $ type instanceof ReflectionNamedType && !$ type ->isBuiltin ()
41- && $ container ->has ($ type ->getName ())
42- ) {
43- $ params [$ name ] = $ container ->get ($ type ->getName ());
44- }
29+ $ this ->propagateContainer ($ value );
30+ $ params [$ name ] = $ this ->lazyLoad ($ value );
4531 }
4632 }
4733
48- return $ this ->stripTrailingNulls ($ params );
34+ return $ this ->stripTrailingNulls (( new Resolver ( $ container ))-> resolveNamed ( $ constructor , $ params) );
4935 }
5036
5137 return parent ::cleanupParams ($ params );
0 commit comments