@@ -338,7 +338,7 @@ class %s extends {$options['class']}
338
338
EOF ;
339
339
340
340
foreach ($ this ->preload as $ class ) {
341
- if (!$ class || str_contains ($ class , '$ ' ) || \in_array ($ class , ['int ' , 'float ' , 'string ' , 'bool ' , 'resource ' , 'object ' , 'array ' , 'null ' , 'callable ' , 'iterable ' , 'mixed ' , 'void ' ], true )) {
341
+ if (!$ class || str_contains ($ class , '$ ' ) || \in_array ($ class , ['int ' , 'float ' , 'string ' , 'bool ' , 'resource ' , 'object ' , 'array ' , 'null ' , 'callable ' , 'iterable ' , 'mixed ' , 'void ' , ' never ' ], true )) {
342
342
continue ;
343
343
}
344
344
if (!(class_exists ($ class , false ) || interface_exists ($ class , false ) || trait_exists ($ class , false )) || (new \ReflectionClass ($ class ))->isUserDefined ()) {
@@ -831,8 +831,7 @@ private function addService(string $id, Definition $definition): array
831
831
if ($ class = $ definition ->getClass ()) {
832
832
$ class = $ class instanceof Parameter ? '% ' .$ class .'% ' : $ this ->container ->resolveEnvPlaceholders ($ class );
833
833
$ return [] = \sprintf (str_starts_with ($ class , '% ' ) ? '@return object A %1$s instance ' : '@return \%s ' , ltrim ($ class , '\\' ));
834
- } elseif ($ definition ->getFactory ()) {
835
- $ factory = $ definition ->getFactory ();
834
+ } elseif ($ factory = $ definition ->getFactory ()) {
836
835
if (\is_string ($ factory ) && !str_starts_with ($ factory , '@= ' )) {
837
836
$ return [] = \sprintf ('@return object An instance returned by %s() ' , $ factory );
838
837
} elseif (\is_array ($ factory ) && (\is_string ($ factory [0 ]) || $ factory [0 ] instanceof Definition || $ factory [0 ] instanceof Reference)) {
@@ -1152,9 +1151,7 @@ private function addNewInstance(Definition $definition, string $return = '', ?st
1152
1151
$ arguments [] = (\is_string ($ i ) ? $ i .': ' : '' ).$ this ->dumpValue ($ value );
1153
1152
}
1154
1153
1155
- if (null !== $ definition ->getFactory ()) {
1156
- $ callable = $ definition ->getFactory ();
1157
-
1154
+ if ($ callable = $ definition ->getFactory ()) {
1158
1155
if ('current ' === $ callable && [0 ] === array_keys ($ definition ->getArguments ()) && \is_array ($ value ) && [0 ] === array_keys ($ value )) {
1159
1156
return $ return .$ this ->dumpValue ($ value [0 ]).$ tail ;
1160
1157
}
@@ -2197,6 +2194,12 @@ private function isSingleUsePrivateNode(ServiceReferenceGraphNode $node): bool
2197
2194
if ($ edge ->isLazy () || !$ value instanceof Definition || !$ value ->isShared ()) {
2198
2195
return false ;
2199
2196
}
2197
+
2198
+ // When the source node is a proxy or ghost, it will construct its references only when the node itself is initialized.
2199
+ // Since the node can be cloned before being fully initialized, we do not know how often its references are used.
2200
+ if ($ this ->getProxyDumper ()->isProxyCandidate ($ value )) {
2201
+ return false ;
2202
+ }
2200
2203
$ ids [$ edge ->getSourceNode ()->getId ()] = true ;
2201
2204
}
2202
2205
@@ -2305,7 +2308,6 @@ private function getAutoloadFile(): ?string
2305
2308
private function getClasses (Definition $ definition , string $ id ): array
2306
2309
{
2307
2310
$ classes = [];
2308
- $ resolve = $ this ->container ->getParameterBag ()->resolveValue (...);
2309
2311
2310
2312
while ($ definition instanceof Definition) {
2311
2313
foreach ($ definition ->getTag ($ this ->preloadTags [0 ]) as $ tag ) {
@@ -2317,24 +2319,24 @@ private function getClasses(Definition $definition, string $id): array
2317
2319
}
2318
2320
2319
2321
if ($ class = $ definition ->getClass ()) {
2320
- $ classes [] = trim ($ resolve ( $ class) , '\\' );
2322
+ $ classes [] = trim ($ class , '\\' );
2321
2323
}
2322
2324
$ factory = $ definition ->getFactory ();
2323
2325
2326
+ if (\is_string ($ factory ) && !str_starts_with ($ factory , '@= ' ) && str_contains ($ factory , ':: ' )) {
2327
+ $ factory = explode (':: ' , $ factory );
2328
+ }
2329
+
2324
2330
if (!\is_array ($ factory )) {
2325
- $ factory = [$ factory ];
2331
+ $ definition = $ factory ;
2332
+ continue ;
2326
2333
}
2327
2334
2328
- if (\is_string ($ factory [0 ])) {
2329
- $ factory [0 ] = $ resolve ($ factory [0 ]);
2335
+ $ definition = $ factory [0 ] ?? null ;
2330
2336
2331
- if (false !== $ i = strrpos ($ factory [0 ], ':: ' )) {
2332
- $ factory [0 ] = substr ($ factory [0 ], 0 , $ i );
2333
- }
2337
+ if (\is_string ($ definition )) {
2334
2338
$ classes [] = trim ($ factory [0 ], '\\' );
2335
2339
}
2336
-
2337
- $ definition = $ factory [0 ];
2338
2340
}
2339
2341
2340
2342
return $ classes ;
0 commit comments