@@ -37,6 +37,7 @@ class AutowirePass extends AbstractRecursivePass
3737 private $ getPreviousValue ;
3838 private $ decoratedMethodIndex ;
3939 private $ decoratedMethodArgumentIndex ;
40+ private $ typesClone ;
4041
4142 public function __construct (bool $ throwOnAutowireException = true )
4243 {
@@ -49,16 +50,16 @@ public function __construct(bool $throwOnAutowireException = true)
4950 public function process (ContainerBuilder $ container )
5051 {
5152 try {
53+ $ this ->typesClone = clone $ this ;
5254 parent ::process ($ container );
5355 } finally {
54- $ this ->types = null ;
55- $ this ->ambiguousServiceTypes = null ;
5656 $ this ->decoratedClass = null ;
5757 $ this ->decoratedId = null ;
5858 $ this ->methodCalls = null ;
5959 $ this ->getPreviousValue = null ;
6060 $ this ->decoratedMethodIndex = null ;
6161 $ this ->decoratedMethodArgumentIndex = null ;
62+ $ this ->typesClone = null ;
6263 }
6364 }
6465
@@ -375,20 +376,22 @@ private function set(string $type, string $id)
375376
376377 private function createTypeNotFoundMessageCallback (TypedReference $ reference , $ label )
377378 {
378- $ container = new ContainerBuilder ($ this ->container ->getParameterBag ());
379- $ container ->setAliases ($ this ->container ->getAliases ());
380- $ container ->setDefinitions ($ this ->container ->getDefinitions ());
381- $ container ->setResourceTracking (false );
379+ if (null === $ this ->typesClone ->container ) {
380+ $ this ->typesClone ->container = new ContainerBuilder ($ this ->container ->getParameterBag ());
381+ $ this ->typesClone ->container ->setAliases ($ this ->container ->getAliases ());
382+ $ this ->typesClone ->container ->setDefinitions ($ this ->container ->getDefinitions ());
383+ $ this ->typesClone ->container ->setResourceTracking (false );
384+ }
382385 $ currentId = $ this ->currentId ;
383386
384- return function () use ($ container , $ reference , $ label , $ currentId ) {
385- return $ this ->createTypeNotFoundMessage ($ container , $ reference , $ label , $ currentId );
386- };
387+ return ( function () use ($ reference , $ label , $ currentId ) {
388+ return $ this ->createTypeNotFoundMessage ($ reference , $ label , $ currentId );
389+ })-> bindTo ( $ this -> typesClone ) ;
387390 }
388391
389- private function createTypeNotFoundMessage (ContainerBuilder $ container , TypedReference $ reference , $ label , string $ currentId )
392+ private function createTypeNotFoundMessage (TypedReference $ reference , $ label , string $ currentId )
390393 {
391- if (!$ r = $ container ->getReflectionClass ($ type = $ reference ->getType (), false )) {
394+ if (!$ r = $ this -> container ->getReflectionClass ($ type = $ reference ->getType (), false )) {
392395 // either $type does not exist or a parent class does not exist
393396 try {
394397 $ resource = new ClassExistenceResource ($ type , false );
@@ -401,8 +404,8 @@ private function createTypeNotFoundMessage(ContainerBuilder $container, TypedRef
401404
402405 $ message = sprintf ('has type "%s" but this class %s. ' , $ type , $ parentMsg ? sprintf ('is missing a parent class (%s) ' , $ parentMsg ) : 'was not found ' );
403406 } else {
404- $ alternatives = $ this ->createTypeAlternatives ($ container , $ reference );
405- $ message = $ container ->has ($ type ) ? 'this service is abstract ' : 'no such service exists ' ;
407+ $ alternatives = $ this ->createTypeAlternatives ($ this -> container , $ reference );
408+ $ message = $ this -> container ->has ($ type ) ? 'this service is abstract ' : 'no such service exists ' ;
406409 $ message = sprintf ('references %s "%s" but %s.%s ' , $ r ->isInterface () ? 'interface ' : 'class ' , $ type , $ message , $ alternatives );
407410
408411 if ($ r ->isInterface () && !$ alternatives ) {
0 commit comments