@@ -738,15 +738,6 @@ protected function {$methodName}($lazyInitialization)
738738EOF ;
739739 }
740740
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-
750741 $ inlinedDefinitions = $ this ->getDefinitionsFromArguments (array ($ definition ));
751742 $ constructorDefinitions = $ this ->getDefinitionsFromArguments (array ($ definition ->getArguments (), $ definition ->getFactory ()));
752743 $ otherDefinitions = new \SplObjectStorage ();
@@ -761,8 +752,18 @@ protected function {$methodName}($lazyInitialization)
761752
762753 $ isSimpleInstance = !$ definition ->getProperties () && !$ definition ->getMethodCalls () && !$ definition ->getConfigurator ();
763754
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+
764766 $ code .=
765- $ this ->addServiceInclude ($ id , $ definition , $ inlinedDefinitions ).
766767 $ this ->addServiceLocalTempVariables ($ id , $ definition , $ constructorDefinitions , $ inlinedDefinitions ).
767768 $ this ->addServiceInlinedDefinitions ($ id , $ definition , $ constructorDefinitions , $ isSimpleInstance ).
768769 $ this ->addServiceInstance ($ id , $ definition , $ isSimpleInstance ).
@@ -815,9 +816,16 @@ private function generateServiceFiles()
815816 $ code = $ this ->addService ($ id , $ definition , $ file );
816817
817818 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 ])));
819826 $ 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 ];
821829 }
822830
823831 yield $ file => $ code ;
0 commit comments