@@ -738,15 +738,6 @@ protected function {$methodName}($lazyInitialization)
738
738
EOF ;
739
739
}
740
740
741
- if ($ this ->getProxyDumper ()->isProxyCandidate ($ definition )) {
742
- $ factoryCode = $ asFile ? "\$this->load(__DIR__.'/%s.php', false) " : '$this->%s(false) ' ;
743
- $ code .= $ this ->getProxyDumper ()->getProxyFactoryCode ($ definition , $ id , sprintf ($ factoryCode , $ methodName ));
744
- }
745
-
746
- if ($ definition ->isDeprecated ()) {
747
- $ code .= sprintf (" @trigger_error(%s, E_USER_DEPRECATED); \n\n" , $ this ->export ($ definition ->getDeprecationMessage ($ id )));
748
- }
749
-
750
741
$ inlinedDefinitions = $ this ->getDefinitionsFromArguments (array ($ definition ));
751
742
$ constructorDefinitions = $ this ->getDefinitionsFromArguments (array ($ definition ->getArguments (), $ definition ->getFactory ()));
752
743
$ otherDefinitions = new \SplObjectStorage ();
@@ -761,8 +752,18 @@ protected function {$methodName}($lazyInitialization)
761
752
762
753
$ isSimpleInstance = !$ definition ->getProperties () && !$ definition ->getMethodCalls () && !$ definition ->getConfigurator ();
763
754
755
+ $ code .= $ this ->addServiceInclude ($ id , $ definition , $ inlinedDefinitions );
756
+
757
+ if ($ this ->getProxyDumper ()->isProxyCandidate ($ definition )) {
758
+ $ factoryCode = $ asFile ? "\$this->load(__DIR__.'/%s.php', false) " : '$this->%s(false) ' ;
759
+ $ code .= $ this ->getProxyDumper ()->getProxyFactoryCode ($ definition , $ id , sprintf ($ factoryCode , $ methodName ));
760
+ }
761
+
762
+ if ($ definition ->isDeprecated ()) {
763
+ $ code .= sprintf (" @trigger_error(%s, E_USER_DEPRECATED); \n\n" , $ this ->export ($ definition ->getDeprecationMessage ($ id )));
764
+ }
765
+
764
766
$ code .=
765
- $ this ->addServiceInclude ($ id , $ definition , $ inlinedDefinitions ).
766
767
$ this ->addServiceLocalTempVariables ($ id , $ definition , $ constructorDefinitions , $ inlinedDefinitions ).
767
768
$ this ->addServiceInlinedDefinitions ($ id , $ definition , $ constructorDefinitions , $ isSimpleInstance ).
768
769
$ this ->addServiceInstance ($ id , $ definition , $ isSimpleInstance ).
@@ -815,9 +816,16 @@ private function generateServiceFiles()
815
816
$ code = $ this ->addService ($ id , $ definition , $ file );
816
817
817
818
if (!$ definition ->isShared ()) {
818
- $ code = implode ("\n" , array_map (function ($ line ) { return $ line ? ' ' .$ line : $ line ; }, explode ("\n" , $ code )));
819
+ $ i = strpos ($ code , "\n\ninclude_once " );
820
+ if (false !== $ i && false !== $ i = strpos ($ code , "\n\n" , 2 + $ i )) {
821
+ $ code = array (substr ($ code , 0 , 2 + $ i ), substr ($ code , 2 + $ i ));
822
+ } else {
823
+ $ code = array ("\n" , $ code );
824
+ }
825
+ $ code [1 ] = implode ("\n" , array_map (function ($ line ) { return $ line ? ' ' .$ line : $ line ; }, explode ("\n" , $ code [1 ])));
819
826
$ factory = sprintf ('$this->factories%s[ \'%s \'] ' , $ definition ->isPublic () ? '' : "['service_container'] " , $ id );
820
- $ code = sprintf ("\n%s = function () { \n%s}; \n\nreturn %1 \$s(); \n" , $ factory , $ code );
827
+ $ code [1 ] = sprintf ("%s = function () { \n%s}; \n\nreturn %1 \$s(); \n" , $ factory , $ code [1 ]);
828
+ $ code = $ code [0 ].$ code [1 ];
821
829
}
822
830
823
831
yield $ file => $ code ;
0 commit comments