@@ -863,18 +863,45 @@ protected function {$methodName}($lazyInitialization)
863
863
}
864
864
}
865
865
866
- if ($ this ->getProxyDumper ()->isProxyCandidate ($ definition )) {
867
- $ factoryCode = $ definition ->isShared () ? ($ asFile ? "\$this->load('%s', false) " : '$this->%s(false) ' ) : '$this->factories[%2$s](false) ' ;
868
- $ factoryCode = $ this ->getProxyDumper ()->getProxyFactoryCode ($ definition , $ id , sprintf ($ factoryCode , $ methodName , $ this ->doExport ($ id )));
866
+ if (!$ definition ->isShared ()) {
867
+ $ factory = sprintf ('$this->factories%s[%s] ' , $ definition ->isPublic () ? '' : "['service_container'] " , $ this ->doExport ($ id ));
868
+ }
869
+
870
+ if ($ isProxyCandidate = $ this ->getProxyDumper ()->isProxyCandidate ($ definition )) {
871
+ if (!$ definition ->isShared ()) {
872
+ $ code .= sprintf (' %s = %1$s ?? ' , $ factory );
873
+
874
+ if ($ asFile ) {
875
+ $ code .= "function () { \n" ;
876
+ $ code .= " return self::do( \$container); \n" ;
877
+ $ code .= " }; \n\n" ;
878
+ } else {
879
+ $ code .= sprintf ("\\Closure::fromCallable([ \$this, '%s']); \n\n" , $ methodName );
880
+ }
881
+ }
882
+
883
+ $ factoryCode = $ asFile ? 'self::do($container, false) ' : sprintf ('$this->%s(false) ' , $ methodName );
884
+ $ factoryCode = $ this ->getProxyDumper ()->getProxyFactoryCode ($ definition , $ id , $ factoryCode );
869
885
$ code .= $ asFile ? preg_replace ('/function \(([^)]*+)\) {/ ' , 'function (\1) use ($container) { ' , $ factoryCode ) : $ factoryCode ;
870
886
}
871
887
872
- $ code .= $ this ->addServiceInclude ($ id , $ definition );
888
+ $ c = $ this ->addServiceInclude ($ id , $ definition );
889
+
890
+ if ('' !== $ c && $ isProxyCandidate && !$ definition ->isShared ()) {
891
+ $ c = implode ("\n" , array_map (function ($ line ) { return $ line ? ' ' .$ line : $ line ; }, explode ("\n" , $ c )));
892
+ $ code .= " static \$include = true; \n\n" ;
893
+ $ code .= " if ( \$include) { \n" ;
894
+ $ code .= $ c ;
895
+ $ code .= " \$include = false; \n" ;
896
+ $ code .= " } \n\n" ;
897
+ } else {
898
+ $ code .= $ c ;
899
+ }
900
+
873
901
$ c = $ this ->addInlineService ($ id , $ definition );
874
902
875
- if (!$ definition ->isShared ()) {
903
+ if (!$ isProxyCandidate && ! $ definition ->isShared ()) {
876
904
$ c = implode ("\n" , array_map (function ($ line ) { return $ line ? ' ' .$ line : $ line ; }, explode ("\n" , $ c )));
877
- $ factory = sprintf ('$this->factories%s[%s] ' , $ definition ->isPublic () ? '' : "['service_container'] " , $ this ->doExport ($ id ));
878
905
$ lazyloadInitialization = $ definition ->isLazy () ? '$lazyLoad = true ' : '' ;
879
906
880
907
$ c = sprintf (" %s = function (%s) { \n%s }; \n\n return %1 \$s(); \n" , $ factory , $ lazyloadInitialization , $ c );
0 commit comments