@@ -711,7 +711,7 @@ private function addService(string $id, Definition $definition, string &$file =
711
711
$ lazyInitialization = '' ;
712
712
}
713
713
714
- $ asFile = $ this ->asFiles && $ definition -> isShared () && !$ this ->isHotPath ($ definition );
714
+ $ asFile = $ this ->asFiles && !$ this ->isHotPath ($ definition );
715
715
$ methodName = $ this ->generateMethodName ($ id );
716
716
if ($ asFile ) {
717
717
$ file = $ methodName .'.php ' ;
@@ -785,7 +785,7 @@ private function addServices(): string
785
785
$ definitions = $ this ->container ->getDefinitions ();
786
786
ksort ($ definitions );
787
787
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 ))) {
789
789
continue ;
790
790
}
791
791
if ($ definition ->isPublic ()) {
@@ -803,8 +803,14 @@ private function generateServiceFiles()
803
803
$ definitions = $ this ->container ->getDefinitions ();
804
804
ksort ($ definitions );
805
805
foreach ($ definitions as $ id => $ definition ) {
806
- if (!$ definition ->isSynthetic () && $ definition -> isShared () && !$ this ->isHotPath ($ definition )) {
806
+ if (!$ definition ->isSynthetic () && !$ this ->isHotPath ($ definition )) {
807
807
$ 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
+
808
814
yield $ file => $ code ;
809
815
}
810
816
}
@@ -1036,7 +1042,7 @@ private function addMethodMap(): string
1036
1042
$ definitions = $ this ->container ->getDefinitions ();
1037
1043
ksort ($ definitions );
1038
1044
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 ))) {
1040
1046
$ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ this ->generateMethodName ($ id )).", \n" ;
1041
1047
}
1042
1048
}
@@ -1050,7 +1056,7 @@ private function addFileMap(): string
1050
1056
$ definitions = $ this ->container ->getDefinitions ();
1051
1057
ksort ($ definitions );
1052
1058
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 )) {
1054
1060
$ code .= sprintf (" %s => __DIR__.'/%s.php', \n" , $ this ->doExport ($ id ), $ this ->generateMethodName ($ id ));
1055
1061
}
1056
1062
}
@@ -1183,9 +1189,9 @@ public function getParameterBag()
1183
1189
}
1184
1190
1185
1191
EOF;
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
+ }
1189
1195
1190
1196
if ($ dynamicPhp ) {
1191
1197
$ 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
1621
1627
if ($ definition ->isShared ()) {
1622
1628
$ code = sprintf ('$this->%s[ \'%s \'] = %s ' , $ definition ->isPublic () ? 'services ' : 'privates ' , $ id , $ code );
1623
1629
}
1624
- } elseif ($ this ->asFiles && $ definition -> isShared () && !$ this ->isHotPath ($ definition )) {
1630
+ } elseif ($ this ->asFiles && !$ this ->isHotPath ($ definition )) {
1625
1631
$ 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
+ }
1626
1636
} else {
1627
1637
$ code = sprintf ('$this->%s() ' , $ this ->generateMethodName ($ id ));
1628
1638
}
0 commit comments