@@ -207,7 +207,7 @@ public function dump(array $options = array())
207
207
208
208
$ code =
209
209
$ this ->startClass ($ options ['class ' ], $ baseClass , $ baseClassWithNamespace ).
210
- $ this ->addServices ().
210
+ $ this ->addServices ($ services ).
211
211
$ this ->addDefaultParametersMethod ()
212
212
;
213
213
@@ -238,7 +238,7 @@ public function dump(array $options = array())
238
238
$ files ['removed-ids.php ' ] = $ c .= "); \n" ;
239
239
}
240
240
241
- foreach ($ this ->generateServiceFiles () as $ file => $ c ) {
241
+ foreach ($ this ->generateServiceFiles ($ services ) as $ file => $ c ) {
242
242
$ files [$ file ] = $ fileStart .$ c ;
243
243
}
244
244
foreach ($ this ->generateProxyClasses () as $ file => $ c ) {
@@ -708,7 +708,7 @@ private function addServiceConfigurator(Definition $definition, string $variable
708
708
return sprintf (" %s( \$%s); \n" , $ callable , $ variableName );
709
709
}
710
710
711
- private function addService (string $ id , Definition $ definition, string & $ file = null ): string
711
+ private function addService (string $ id , Definition $ definition ): array
712
712
{
713
713
$ this ->definitionVariables = new \SplObjectStorage ();
714
714
$ this ->referenceVariables = array ();
@@ -759,6 +759,7 @@ private function addService(string $id, Definition $definition, string &$file =
759
759
$ file = $ methodName .'.php ' ;
760
760
$ code = " // Returns the $ public ' $ id' $ shared$ autowired service. \n\n" ;
761
761
} else {
762
+ $ file = null ;
762
763
$ code = <<<EOF
763
764
764
765
/* {$ this ->docStar }
@@ -825,36 +826,38 @@ protected function {$methodName}($lazyInitialization)
825
826
$ this ->definitionVariables = null ;
826
827
$ this ->referenceVariables = null ;
827
828
828
- return $ code ;
829
+ return array ( $ file , $ code) ;
829
830
}
830
831
831
- private function addServices (): string
832
+ private function addServices (array & $ services = null ): string
832
833
{
833
834
$ publicServices = $ privateServices = '' ;
834
835
$ definitions = $ this ->container ->getDefinitions ();
835
836
ksort ($ definitions );
836
837
foreach ($ definitions as $ id => $ definition ) {
837
- if ($ definition ->isSynthetic () || ($ this ->asFiles && !$ this ->isHotPath ($ definition ))) {
838
+ $ services [$ id ] = $ definition ->isSynthetic () ? null : $ this ->addService ($ id , $ definition );
839
+ }
840
+
841
+ foreach ($ definitions as $ id => $ definition ) {
842
+ if (!(list ($ file , $ code ) = $ services [$ id ]) || null !== $ file ) {
838
843
continue ;
839
844
}
840
845
if ($ definition ->isPublic ()) {
841
- $ publicServices .= $ this -> addService ( $ id , $ definition ) ;
846
+ $ publicServices .= $ code ;
842
847
} elseif (!$ this ->isTrivialInstance ($ definition ) || isset ($ this ->locatedIds [$ id ])) {
843
- $ privateServices .= $ this -> addService ( $ id , $ definition ) ;
848
+ $ privateServices .= $ code ;
844
849
}
845
850
}
846
851
847
852
return $ publicServices .$ privateServices ;
848
853
}
849
854
850
- private function generateServiceFiles ()
855
+ private function generateServiceFiles (array $ services )
851
856
{
852
857
$ definitions = $ this ->container ->getDefinitions ();
853
858
ksort ($ definitions );
854
859
foreach ($ definitions as $ id => $ definition ) {
855
- if (!$ definition ->isSynthetic () && !$ this ->isHotPath ($ definition ) && ($ definition ->isPublic () || !$ this ->isTrivialInstance ($ definition ) || isset ($ this ->locatedIds [$ id ]))) {
856
- $ code = $ this ->addService ($ id , $ definition , $ file );
857
-
860
+ if ((list ($ file , $ code ) = $ services [$ id ]) && null !== $ file && ($ definition ->isPublic () || !$ this ->isTrivialInstance ($ definition ) || isset ($ this ->locatedIds [$ id ]))) {
858
861
if (!$ definition ->isShared ()) {
859
862
$ i = strpos ($ code , "\n\ninclude_once " );
860
863
if (false !== $ i && false !== $ i = strpos ($ code , "\n\n" , 2 + $ i )) {
0 commit comments