@@ -528,7 +528,7 @@ private function addServiceInlinedDefinitions(string $id, Definition $definition
528
528
529
529
$ code .= $ this ->addNewInstance ($ def , ' $ ' .$ name .' = ' , $ id );
530
530
531
- if (!$ this ->hasReference ($ id , array ($ def ->getProperties (), $ def ->getMethodCalls (), $ def ->getConfigurator ()), true )) {
531
+ if (!$ this ->hasReference ($ id , array ($ def ->getProperties (), $ def ->getMethodCalls (), $ def ->getConfigurator ()), true , $ inlinedDefinitions )) {
532
532
$ code .= $ this ->addServiceProperties ($ def , $ name );
533
533
$ code .= $ this ->addServiceMethodCalls ($ def , $ name );
534
534
$ code .= $ this ->addServiceConfigurator ($ def , $ name );
@@ -657,7 +657,7 @@ private function addServiceInlinedDefinitionsSetup(string $id, Definition $defin
657
657
{
658
658
$ code = '' ;
659
659
foreach ($ inlinedDefinitions as $ def ) {
660
- if ($ definition === $ def || !$ this ->hasReference ($ id , array ($ def ->getProperties (), $ def ->getMethodCalls (), $ def ->getConfigurator ()), true )) {
660
+ if ($ definition === $ def || !$ this ->hasReference ($ id , array ($ def ->getProperties (), $ def ->getMethodCalls (), $ def ->getConfigurator ()), true , $ inlinedDefinitions )) {
661
661
continue ;
662
662
}
663
663
@@ -775,6 +775,7 @@ protected function {$methodName}($lazyInitialization)
775
775
776
776
$ inlinedDefinitions = $ this ->getDefinitionsFromArguments (array ($ definition ));
777
777
$ constructorDefinitions = $ this ->getDefinitionsFromArguments (array ($ definition ->getArguments (), $ definition ->getFactory ()));
778
+ unset($ constructorDefinitions [$ definition ]); // ensures $definition will be last
778
779
$ otherDefinitions = new \SplObjectStorage ();
779
780
$ serviceCalls = array ();
780
781
@@ -1091,6 +1092,9 @@ private function addRemovedIds(): string
1091
1092
$ ids = array_keys ($ ids );
1092
1093
sort ($ ids );
1093
1094
foreach ($ ids as $ id ) {
1095
+ if (preg_match ('/^\.\d+_[^~]++~[._a-zA-Z\d]{7}$/ ' , $ id )) {
1096
+ continue ;
1097
+ }
1094
1098
$ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
1095
1099
}
1096
1100
@@ -1450,15 +1454,15 @@ private function getDefinitionsFromArguments(array $arguments, bool $isConstruct
1450
1454
return $ definitions ;
1451
1455
}
1452
1456
1453
- private function hasReference (string $ id , array $ arguments , bool $ deep = false , array &$ visited = array ()): bool
1457
+ private function hasReference (string $ id , array $ arguments , bool $ deep = false , \ SplObjectStorage $ inlinedDefinitions = null , array &$ visited = array ()): bool
1454
1458
{
1455
1459
if (!isset ($ this ->circularReferences [$ id ])) {
1456
1460
return false ;
1457
1461
}
1458
1462
1459
1463
foreach ($ arguments as $ argument ) {
1460
1464
if (\is_array ($ argument )) {
1461
- if ($ this ->hasReference ($ id , $ argument , $ deep , $ visited )) {
1465
+ if ($ this ->hasReference ($ id , $ argument , $ deep , $ inlinedDefinitions , $ visited )) {
1462
1466
return true ;
1463
1467
}
1464
1468
@@ -1477,6 +1481,9 @@ private function hasReference(string $id, array $arguments, bool $deep = false,
1477
1481
1478
1482
$ service = $ this ->container ->getDefinition ($ argumentId );
1479
1483
} elseif ($ argument instanceof Definition) {
1484
+ if (isset ($ inlinedDefinitions [$ argument ])) {
1485
+ return true ;
1486
+ }
1480
1487
$ service = $ argument ;
1481
1488
} else {
1482
1489
continue ;
@@ -1488,7 +1495,7 @@ private function hasReference(string $id, array $arguments, bool $deep = false,
1488
1495
continue ;
1489
1496
}
1490
1497
1491
- if ($ this ->hasReference ($ id , array ($ service ->getArguments (), $ service ->getFactory (), $ service ->getProperties (), $ service ->getMethodCalls (), $ service ->getConfigurator ()), $ deep , $ visited )) {
1498
+ if ($ this ->hasReference ($ id , array ($ service ->getArguments (), $ service ->getFactory (), $ service ->getProperties (), $ service ->getMethodCalls (), $ service ->getConfigurator ()), $ deep , $ inlinedDefinitions , $ visited )) {
1492
1499
return true ;
1493
1500
}
1494
1501
}
0 commit comments