1616use Symfony \Component \DependencyInjection \Definition ;
1717use Symfony \Component \DependencyInjection \LazyProxy \ProxyHelper ;
1818use Symfony \Component \DependencyInjection \Reference ;
19+ use Symfony \Component \DependencyInjection \TypedReference ;
1920
2021/**
2122 * Overwrites a service but keeps the overridden one.
@@ -72,19 +73,17 @@ public function process(ContainerBuilder $container)
7273
7374 private function autowire (ContainerBuilder $ container , Definition $ definition , string $ renamedId ): void
7475 {
75- if (
76- !$ definition ->isAutowired () ||
76+ if (!$ definition ->isAutowired () ||
7777 null === ($ innerClass = $ container ->findDefinition ($ renamedId )->getClass ()) ||
7878 !($ reflectionClass = $ container ->getReflectionClass ($ definition ->getClass ())) ||
79- !$ reflectionMethod = $ reflectionClass ->getConstructor ()
79+ !$ constructor = $ reflectionClass ->getConstructor ()
8080 ) {
8181 return ;
8282 }
8383
8484 $ innerIndex = null ;
85- foreach ($ reflectionMethod ->getParameters () as $ index => $ parameter ) {
86- if (
87- null === ($ type = ProxyHelper::getTypeHint ($ reflectionMethod , $ parameter , true )) ||
85+ foreach ($ constructor ->getParameters () as $ index => $ parameter ) {
86+ if (null === ($ type = ProxyHelper::getTypeHint ($ constructor , $ parameter , true )) ||
8887 !is_a ($ innerClass , $ type , true )
8988 ) {
9089 continue ;
@@ -99,7 +98,7 @@ private function autowire(ContainerBuilder $container, Definition $definition, s
9998 }
10099
101100 if (null !== $ innerIndex ) {
102- $ definition ->setArgument ($ innerIndex , new Reference ($ renamedId ));
101+ $ definition ->setArgument ($ innerIndex , new TypedReference ($ renamedId, $ innerClass ));
103102 }
104103 }
105104}
0 commit comments