@@ -711,7 +711,7 @@ private function addService(string $id, Definition $definition, string &$file =
711711 $ lazyInitialization = '' ;
712712 }
713713
714- $ asFile = $ this ->asFiles && $ definition -> isShared () && !$ this ->isHotPath ($ definition );
714+ $ asFile = $ this ->asFiles && !$ this ->isHotPath ($ definition );
715715 $ methodName = $ this ->generateMethodName ($ id );
716716 if ($ asFile ) {
717717 $ file = $ methodName .'.php ' ;
@@ -785,7 +785,7 @@ private function addServices(): string
785785 $ definitions = $ this ->container ->getDefinitions ();
786786 ksort ($ definitions );
787787 foreach ($ definitions as $ id => $ definition ) {
788- if ($ definition ->isSynthetic () || ($ this ->asFiles && $ definition -> isShared () && !$ this ->isHotPath ($ definition ))) {
788+ if ($ definition ->isSynthetic () || ($ this ->asFiles && !$ this ->isHotPath ($ definition ))) {
789789 continue ;
790790 }
791791 if ($ definition ->isPublic ()) {
@@ -803,8 +803,14 @@ private function generateServiceFiles()
803803 $ definitions = $ this ->container ->getDefinitions ();
804804 ksort ($ definitions );
805805 foreach ($ definitions as $ id => $ definition ) {
806- if (!$ definition ->isSynthetic () && $ definition -> isShared () && !$ this ->isHotPath ($ definition )) {
806+ if (!$ definition ->isSynthetic () && !$ this ->isHotPath ($ definition )) {
807807 $ code = $ this ->addService ($ id , $ definition , $ file );
808+
809+ if (!$ definition ->isShared ()) {
810+ $ factory = sprintf ('$this->factories%s[ \'%s \'] ' , $ definition ->isPublic () ? '' : "['service_container'] " , $ id );
811+ $ code = sprintf ("\n%s = function () { \n%s}; \n\nreturn %1 \$s(); \n" , $ factory , $ code );
812+ }
813+
808814 yield $ file => $ code ;
809815 }
810816 }
@@ -1036,7 +1042,7 @@ private function addMethodMap(): string
10361042 $ definitions = $ this ->container ->getDefinitions ();
10371043 ksort ($ definitions );
10381044 foreach ($ definitions as $ id => $ definition ) {
1039- if (!$ definition ->isSynthetic () && $ definition ->isPublic () && (!$ this ->asFiles || ! $ definition -> isShared () || $ this ->isHotPath ($ definition ))) {
1045+ if (!$ definition ->isSynthetic () && $ definition ->isPublic () && (!$ this ->asFiles || $ this ->isHotPath ($ definition ))) {
10401046 $ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ this ->generateMethodName ($ id )).", \n" ;
10411047 }
10421048 }
@@ -1050,7 +1056,7 @@ private function addFileMap(): string
10501056 $ definitions = $ this ->container ->getDefinitions ();
10511057 ksort ($ definitions );
10521058 foreach ($ definitions as $ id => $ definition ) {
1053- if (!$ definition ->isSynthetic () && $ definition ->isPublic () && $ definition -> isShared () && !$ this ->isHotPath ($ definition )) {
1059+ if (!$ definition ->isSynthetic () && $ definition ->isPublic () && !$ this ->isHotPath ($ definition )) {
10541060 $ code .= sprintf (" %s => __DIR__.'/%s.php', \n" , $ this ->doExport ($ id ), $ this ->generateMethodName ($ id ));
10551061 }
10561062 }
@@ -1183,9 +1189,9 @@ public function getParameterBag()
11831189 }
11841190
11851191EOF;
1186- if (!$ this ->asFiles ) {
1187- $ code = preg_replace ('/^.*buildParameters.*\n.*\n.*\n/m ' , '' , $ code );
1188- }
1192+ if (!$ this ->asFiles ) {
1193+ $ code = preg_replace ('/^.*buildParameters.*\n.*\n.*\n/m ' , '' , $ code );
1194+ }
11891195
11901196 if ($ dynamicPhp ) {
11911197 $ loadedDynamicParameters = $ this ->exportParameters (array_combine (array_keys ($ dynamicPhp ), array_fill (0 , count ($ dynamicPhp ), false )), '' , 8 );
@@ -1621,8 +1627,12 @@ private function getServiceCall(string $id, Reference $reference = null): string
16211627 if ($ definition ->isShared ()) {
16221628 $ code = sprintf ('$this->%s[ \'%s \'] = %s ' , $ definition ->isPublic () ? 'services ' : 'privates ' , $ id , $ code );
16231629 }
1624- } elseif ($ this ->asFiles && $ definition -> isShared () && !$ this ->isHotPath ($ definition )) {
1630+ } elseif ($ this ->asFiles && !$ this ->isHotPath ($ definition )) {
16251631 $ code = sprintf ("\$this->load(__DIR__.'/%s.php') " , $ this ->generateMethodName ($ id ));
1632+ if (!$ definition ->isShared ()) {
1633+ $ factory = sprintf ('$this->factories%s[ \'%s \'] ' , $ definition ->isPublic () ? '' : "['service_container'] " , $ id );
1634+ $ code = sprintf ('(isset(%s) ? %1$s() : %s) ' , $ factory , $ code );
1635+ }
16261636 } else {
16271637 $ code = sprintf ('$this->%s() ' , $ this ->generateMethodName ($ id ));
16281638 }
0 commit comments