@@ -1048,12 +1048,35 @@ private function createService(Definition $definition, array &$inlineServices, b
1048
1048
}
1049
1049
1050
1050
$ parameterBag = $ this ->getParameterBag ();
1051
+ $ class = ($ parameterBag ->resolveValue ($ definition ->getClass ()) ?: (['Closure ' , 'fromCallable ' ] === $ definition ->getFactory () ? 'Closure ' : null ));
1051
1052
1052
- if (true === $ tryProxy && $ definition ->isLazy () && !$ tryProxy = !($ proxy = $ this ->proxyInstantiator ??= new LazyServiceInstantiator ()) || $ proxy instanceof RealServiceInstantiator) {
1053
+ if ('Closure ' === $ class && $ definition ->isLazy () && ['Closure ' , 'fromCallable ' ] === $ definition ->getFactory ()) {
1054
+ $ callable = $ parameterBag ->unescapeValue ($ parameterBag ->resolveValue ($ definition ->getArgument (0 )));
1055
+
1056
+ if ($ callable instanceof Reference || $ callable instanceof Definition) {
1057
+ $ callable = [$ callable , '__invoke ' ];
1058
+ }
1059
+
1060
+ if (\is_array ($ callable ) && (
1061
+ $ callable [0 ] instanceof Reference
1062
+ || $ callable [0 ] instanceof Definition && !isset ($ inlineServices [spl_object_hash ($ callable [0 ])])
1063
+ )) {
1064
+ $ proxy = function (...$ arguments ) use ($ callable , &$ inlineServices ) {
1065
+ return $ this ->doResolveServices ($ callable , $ inlineServices )(...$ arguments );
1066
+ };
1067
+ $ this ->shareService ($ definition , $ proxy , $ id , $ inlineServices );
1068
+
1069
+ return $ proxy ;
1070
+ }
1071
+ }
1072
+
1073
+ if (true === $ tryProxy && $ definition ->isLazy () && 'Closure ' !== $ class
1074
+ && !$ tryProxy = !($ proxy = $ this ->proxyInstantiator ??= new LazyServiceInstantiator ()) || $ proxy instanceof RealServiceInstantiator
1075
+ ) {
1053
1076
$ proxy = $ proxy ->instantiateProxy (
1054
1077
$ this ,
1055
1078
(clone $ definition )
1056
- ->setClass ($ parameterBag -> resolveValue ( $ definition -> getClass ()) )
1079
+ ->setClass ($ class )
1057
1080
->setTags (($ definition ->hasTag ('proxy ' ) ? ['proxy ' => $ parameterBag ->resolveValue ($ definition ->getTag ('proxy ' ))] : []) + $ definition ->getTags ()),
1058
1081
$ id , function ($ proxy = false ) use ($ definition , &$ inlineServices , $ id ) {
1059
1082
return $ this ->createService ($ definition , $ inlineServices , true , $ id , $ proxy );
@@ -1102,7 +1125,7 @@ private function createService(Definition $definition, array &$inlineServices, b
1102
1125
}
1103
1126
}
1104
1127
} else {
1105
- $ r = new \ReflectionClass ($ parameterBag -> resolveValue ( $ definition -> getClass ()) );
1128
+ $ r = new \ReflectionClass ($ class );
1106
1129
1107
1130
if (\is_object ($ tryProxy )) {
1108
1131
if ($ r ->getConstructor ()) {
0 commit comments