@@ -864,13 +864,23 @@ protected function {$methodName}($lazyInitialization)
864
864
}
865
865
866
866
if ($ this ->getProxyDumper ()->isProxyCandidate ($ definition )) {
867
- $ factoryCode = $ asFile ? "\$this->load('%s', false) " : '$this->%s(false) ' ;
868
- $ factoryCode = $ this ->getProxyDumper ()->getProxyFactoryCode ($ definition , $ id , sprintf ($ factoryCode , $ methodName ));
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 ) ));
869
869
$ code .= $ asFile ? preg_replace ('/function \(([^)]*+)\) {/ ' , 'function (\1) use ($container) { ' , $ factoryCode ) : $ factoryCode ;
870
870
}
871
871
872
872
$ code .= $ this ->addServiceInclude ($ id , $ definition );
873
- $ code .= $ this ->addInlineService ($ id , $ definition );
873
+ $ c = $ this ->addInlineService ($ id , $ definition );
874
+
875
+ if (!$ definition ->isShared ()) {
876
+ $ 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
+ $ lazyloadInitialization = $ definition ->isLazy () ? '$lazyLoad = true ' : '' ;
879
+
880
+ $ c = sprintf (" %s = function (%s) { \n%s }; \n\n return %1 \$s(); \n" , $ factory , $ lazyloadInitialization , $ c );
881
+ }
882
+
883
+ $ code .= $ c ;
874
884
}
875
885
876
886
if ($ asFile ) {
@@ -1880,10 +1890,14 @@ private function getServiceCall(string $id, Reference $reference = null): string
1880
1890
$ code = sprintf ('$this->%s[%s] = %s ' , $ definition ->isPublic () ? 'services ' : 'privates ' , $ this ->doExport ($ id ), $ code );
1881
1891
}
1882
1892
$ code = "( $ code) " ;
1883
- } elseif ($ this ->asFiles && !$ this ->inlineFactories && !$ this ->isHotPath ($ definition )) {
1884
- $ code = sprintf ("\$this->load('%s') " , $ this ->generateMethodName ($ id ));
1885
1893
} else {
1886
- $ code = sprintf ('$this->%s() ' , $ this ->generateMethodName ($ id ));
1894
+ $ code = $ this ->asFiles && !$ this ->inlineFactories && !$ this ->isHotPath ($ definition ) ? "\$this->load('%s') " : '$this->%s() ' ;
1895
+ $ code = sprintf ($ code , $ this ->generateMethodName ($ id ));
1896
+
1897
+ if (!$ definition ->isShared ()) {
1898
+ $ factory = sprintf ('$this->factories%s[%s] ' , $ definition ->isPublic () ? '' : "['service_container'] " , $ this ->doExport ($ id ));
1899
+ $ code = sprintf ('(isset(%s) ? %1$s() : %s) ' , $ factory , $ code );
1900
+ }
1887
1901
}
1888
1902
if ($ definition ->isShared () && !isset ($ this ->singleUsePrivateIds [$ id ])) {
1889
1903
$ code = sprintf ('($this->%s[%s] ?? %s) ' , $ definition ->isPublic () ? 'services ' : 'privates ' , $ this ->doExport ($ id ), $ code );
0 commit comments