@@ -37,6 +37,7 @@ class AutowirePass extends AbstractRecursivePass
37
37
private $ getPreviousValue ;
38
38
private $ decoratedMethodIndex ;
39
39
private $ decoratedMethodArgumentIndex ;
40
+ private $ typesClone ;
40
41
41
42
public function __construct (bool $ throwOnAutowireException = true )
42
43
{
@@ -49,16 +50,16 @@ public function __construct(bool $throwOnAutowireException = true)
49
50
public function process (ContainerBuilder $ container )
50
51
{
51
52
try {
53
+ $ this ->typesClone = clone $ this ;
52
54
parent ::process ($ container );
53
55
} finally {
54
- $ this ->types = null ;
55
- $ this ->ambiguousServiceTypes = null ;
56
56
$ this ->decoratedClass = null ;
57
57<
8000
/code>
$ this ->decoratedId = null ;
58
58
$ this ->methodCalls = null ;
59
59
$ this ->getPreviousValue = null ;
60
60
$ this ->decoratedMethodIndex = null ;
61
61
$ this ->decoratedMethodArgumentIndex = null ;
62
+ $ this ->typesClone = null ;
62
63
}
63
64
}
64
65
@@ -375,20 +376,22 @@ private function set(string $type, string $id)
375
376
376
377
private function createTypeNotFoundMessageCallback (TypedReference $ reference , $ label )
377
378
{
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
+ }
382
385
$ currentId = $ this ->currentId ;
383
386
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 ) ;
387
390
}
388
391
389
- private function createTypeNotFoundMessage (ContainerBuilder $ container , TypedReference $ reference , $ label , string $ currentId )
392
+ private function createTypeNotFoundMessage (TypedReference $ reference , $ label , string $ currentId )
390
393
{
391
- if (!$ r = $ container ->getReflectionClass ($ type = $ reference ->getType (), false )) {
394
+ if (!$ r = $ this -> container ->getReflectionClass ($ type = $ reference ->getType (), false )) {
392
395
// either $type does not exist or a parent class does not exist
393
396
try {
394
397
$ resource = new ClassExistenceResource ($ type , false );
@@ -401,8 +404,8 @@ private function createTypeNotFoundMessage(ContainerBuilder $container, TypedRef
401
404
402
405
$ message = sprintf ('has type "%s" but this class %s. ' , $ type , $ parentMsg ? sprintf ('is missing a parent class (%s) ' , $ parentMsg ) : 'was not found ' );
403
406
} 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 ' ;
406
409
$ message = sprintf ('references %s "%s" but %s.%s ' , $ r ->isInterface () ? 'interface ' : 'class ' , $ type , $ message , $ alternatives );
407
410
408
411
if ($ r ->isInterface () && !$ alternatives ) {
0 commit comments