@@ -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,15 @@ 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
+ $ code = implode ("\n" , array_map (function ($ line ) { return $ line ? ' ' .$ line : $ line ; }, explode ("\n" , $ code )));
811
+ $ factory = sprintf ('$this->factories%s[ \'%s \'] ' , $ definition ->isPublic () ? '' : "['service_container'] " , $ id );
812
+ $ code = sprintf ("\n%s = function () { \n%s}; \n\nreturn %1 \$s(); \n" , $ factory , $ code );
813
+ }
814
+
808
815
yield $ file => $ code ;
809
816
}
810
817
}
@@ -1036,7 +1043,7 @@ private function addMethodMap(): string
1036
1043
$ definitions = $ this ->container ->getDefinitions ();
1037
1044
ksort ($ definitions );
1038
1045
foreach ($ definitions as $ id => $ definition ) {
1039
- if (!$ definition ->isSynthetic () && $ definition ->isPublic () && (!$ this ->asFiles || ! $ definition -> isShared () || $ this ->isHotPath ($ definition ))) {
1046
+ if (!$ definition ->isSynthetic () && $ definition ->isPublic () && (!$ this ->asFiles || $ this ->isHotPath ($ definition ))) {
1040
1047
$ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ this ->generateMethodName ($ id )).", \n" ;
1041
1048
}
1042
1049
}
@@ -1050,7 +1057,7 @@ private function addFileMap(): string
1050
1057
$ definitions = $ this ->container ->getDefinitions ();
1051
1058
ksort ($ definitions );
1052
1059
foreach ($ definitions as $ id => $ definition ) {
1053
- if (!$ definition ->isSynthetic () && $ definition ->isPublic () && $ definition -> isShared () && !$ this ->isHotPath ($ definition )) {
1060
+ if (!$ definition ->isSynthetic () && $ definition ->isPublic () && !$ this ->isHotPath ($ definition )) {
1054
1061
$ code .= sprintf (" %s => __DIR__.'/%s.php', \n" , $ this ->doExport ($ id ), $ this ->generateMethodName ($ id ));
1055
1062
}
1056
1063
}
@@ -1621,8 +1628,12 @@ private function getServiceCall(string $id, Reference $reference = null): string
1621
1628
if ($ definition ->isShared ()) {
1622
1629
$ code = sprintf ('$this->%s[ \'%s \'] = %s ' , $ definition ->isPublic () ? 'services ' : 'privates ' , $ id , $ code );
1623
1630
}
1624
- } elseif ($ this ->asFiles && $ definition -> isShared () && !$ this ->isHotPath ($ definition )) {
1631
+ } elseif ($ this ->asFiles && !$ this ->isHotPath ($ definition )) {
1625
1632
$ code = sprintf ("\$this->load(__DIR__.'/%s.php') " , $ this ->generateMethodName ($ id ));
1633
+ if (!$ definition ->isShared ()) {
1634
+ $ factory = sprintf ('$this->factories%s[ \'%s \'] ' , $ definition ->isPublic () ? '' : "['service_container'] " , $ id );
1635
+ $ code = sprintf ('(isset(%s) ? %1$s() : %s) ' , $ factory , $ code );
1636
+ }
1626
1637
} else {
1627
1638
$ code = sprintf ('$this->%s() ' , $ this ->generateMethodName ($ id ));
1628
1639
}
0 commit comments