@@ -554,7 +554,7 @@ private function generateProxyClasses(): array
554
554
$ proxyDumper = $ this ->getProxyDumper ();
555
555
ksort ($ definitions );
556
556
foreach ($ definitions as $ definition ) {
557
- if (!$ proxyDumper ->isProxyCandidate ($ definition )) {
557
+ if (!$ definition = $ this ->isProxyCandidate ($ definition )) {
558
558
continue ;
559
559
}
560
560
if (isset ($ alreadyGenerated [$ class = $ definition ->getClass ()])) {
@@ -599,11 +599,11 @@ private function generateProxyClasses(): array
599
599
return $ proxyClasses ;
600
600
}
601
601
602
- private function addServiceInclude (string $ cId , Definition $ definition ): string
602
+ private function addServiceInclude (string $ cId , Definition $ definition, bool $ isProxyCandidate ): string
603
603
{
604
604
$ code = '' ;
605
605
606
- if ($ this ->inlineRequires && (!$ this ->isHotPath ($ definition ) || $ this -> getProxyDumper ()-> isProxyCandidate ( $ definition ) )) {
606
+ if ($ this ->inlineRequires && (!$ this ->isHotPath ($ definition ) || $ isProxyCandidate )) {
607
607
$ lineage = [];
608
608
foreach ($ this ->inlinedDefinitions as $ def ) {
609
609
if (!$ def ->isDeprecated ()) {
@@ -658,7 +658,7 @@ private function addServiceInstance(string $id, Definition $definition, bool $is
658
658
}
659
659
660
660
$ asGhostObject = false ;
661
- $ isProxyCandidate = $ this ->getProxyDumper ()-> isProxyCandidate ($ definition , $ asGhostObject );
661
+ $ isProxyCandidate = $ this ->isProxyCandidate ($ definition , $ asGhostObject );
662
662
$ instantiation = '' ;
663
663
664
664
$ lastWitherIndex = null ;
@@ -886,7 +886,9 @@ protected function {$methodName}($lazyInitialization)
886
886
}
887
887
888
888
$ asGhostObject = false ;
889
- if ($ isProxyCandidate = $ this ->getProxyDumper ()->isProxyCandidate ($ definition , $ asGhostObject )) {
889
+ if ($ isProxyCandidate = $ this ->isProxyCandidate ($ definition , $ asGhostObject )) {
890
+ $ definition = $ isProxyCandidate ;
891
+
890
892
if (!$ definition ->isShared ()) {
891
893
$ code .= sprintf (' %s ??= ' , $ factory );
892
894
@@ -905,7 +907,7 @@ protected function {$methodName}($lazyInitialization)
905
907
$ code .= $ asFile ? preg_replace ('/function \(([^)]*+)\)( {|:)/ ' , 'function (\1) use ($container)\2 ' , $ factoryCode ) : $ factoryCode ;
906
908
}
907
909
908
- $ c = $ this ->addServiceInclude ($ id , $ definition );
910
+ $ c = $ this ->addServiceInclude ($ id , $ definition, null !== $ isProxyCandidate );
909
911
910
912
if ('' !== $ c && $ isProxyCandidate && !$ definition ->isShared ()) {
911
913
$ c = implode ("\n" , array_map (function ($ line ) { return $ line ? ' ' .$ line : $ line ; }, explode ("\n" , $ c )));
@@ -1044,7 +1046,7 @@ private function addInlineService(string $id, Definition $definition, Definition
1044
1046
}
1045
1047
1046
1048
$ asGhostObject = false ;
1047
- $ isProxyCandidate = $ this ->getProxyDumper ()-> isProxyCandidate ($ inlineDef , $ asGhostObject );
1049
+ $ isProxyCandidate = $ this ->isProxyCandidate ($ inlineDef , $ asGhostObject );
1048
1050
1049
1051
if (isset ($ this ->definitionVariables [$ inlineDef ])) {
1050
1052
$ isSimpleInstance = false ;
@@ -1307,9 +1309,8 @@ protected function load($file, $lazyLoad = true)
1307
1309
EOF;
1308
1310
}
1309
1311
1310
- $ proxyDumper = $ this ->getProxyDumper ();
1311
1312
foreach ($ this ->container ->getDefinitions () as $ definition ) {
1312
- if (!$ proxyDumper -> isProxyCandidate ( $ definition ) ) {
1313
+ if (!$ definition -> isLazy () || $ this -> getProxyDumper () instanceof NullDumper ) {
1313
1314
continue ;
1314
1315
}
1315
1316
@@ -1496,7 +1497,7 @@ private function addInlineRequires(bool $hasProxyClasses): string
1496
1497
foreach ($ hotPathServices as $ id => $ tags ) {
1497
1498
$ definition = $ this ->container ->getDefinition ($ id );
1498
1499
1499
- if ($ this -> getProxyDumper ()-> isProxyCandidate ( $ definition ) ) {
1500
+ if ($ definition -> isLazy () && ! $ this -> getProxyDumper () instanceof NullDumper ) {
1500
1501
continue ;
1501
1502
}
1502
1503
@@ -1880,7 +1881,7 @@ private function dumpValue(mixed $value, bool $interpolate = true): string
1880
1881
}
1881
1882
1882
1883
$ asGhostObject = false ;
1883
- $ this ->getProxyDumper ()-> isProxyCandidate ($ value , $ asGhostObject );
1884
+ $ this ->isProxyCandidate ($ value , $ asGhostObject );
1884
1885
1885
1886
return $ this ->addNewInstance ($ value , '' , null , $ asGhostObject );
1886
1887
} elseif ($ value instanceof Variable) {
@@ -2252,6 +2253,7 @@ private function getAutoloadFile(): ?string
2252
2253
private function getClasses (Definition $ definition , string $ id ): array
2253
2254
{
2254
2255
$ classes = [];
2256
+ $ resolve = $ this ->container ->getParameterBag ()->resolveValue (...);
2255
2257
2256
2258
while ($ definition instanceof Definition) {
2257
2259
foreach ($ definition ->getTag ($ this ->preloadTags [0 ]) as $ tag ) {
@@ -2263,7 +2265,7 @@ private function getClasses(Definition $definition, string $id): array
2263
2265
}
2264
2266
2265
2267
if ($ class = $ definition ->getClass ()) {
2266
- $ classes [] = trim ($ class , '\\' );
2268
+ $ classes [] = trim ($ resolve ( $ class) , '\\' );
2267
2269
}
2268
2270
$ factory = $ definition ->getFactory ();
2269
2271
@@ -2272,6 +2274,8 @@ private function getClasses(Definition $definition, string $id): array
2272
2274
}
2273
2275
2274
2276
if (\is_string ($ factory [0 ])) {
2277
+ $ factory [0 ] = $ resolve ($ factory [0 ]);
2278
+
2275
2279
if (false !== $ i = strrpos ($ factory [0 ], ':: ' )) {
2276
2280
$ factory [0 ] = substr ($ factory [0 ], 0 , $ i );
2277
2281
}
@@ -2283,4 +2287,20 @@ private function getClasses(Definition $definition, string $id): array
2283
2287
2284
2288
return $ classes ;
2285
2289
}
2290
+
2291
+ private function isProxyCandidate (Definition $ definition , bool &$ asGhostObject = null ): ?Definition
2292
+ {
2293
+ $ asGhostObject = false ;
2294
+
2295
+ if (!$ definition ->isLazy () || ($ proxyDumper = $ this ->getProxyDumper ()) instanceof NullDumper) {
2296
+ return null ;
2297
+ }
2298
+
2299
+ $ bag = $ this ->container ->getParameterBag ();
2300
+ $ definition = (clone $ definition )
2301
+ ->setClass ($ bag ->resolveValue ($ definition ->getClass ()))
2302
+ ->setTags ($ bag ->resolveValue ($ definition ->getTags ()));
2303
+
2304
+ return $ proxyDumper ->isProxyCandidate ($ definition , $ asGhostObject ) ? $ definition : null ;
2305
+ }
2286
2306
}
0 commit comments