@@ -680,6 +680,7 @@ private function addServices()
680680 private function addNewInstance (Definition $ definition , $ return , $ instantiation , $ id )
681681 {
682682 $ class = $ this ->dumpValue ($ definition ->getClass ());
683+ $ return = ' ' .$ return .$ instantiation ;
683684
684685 $ arguments = array ();
685686 foreach ($ definition ->getArguments () as $ value ) {
@@ -695,7 +696,7 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
695696
696697 if ($ callable [0 ] instanceof Reference
697698 || ($ callable [0 ] instanceof Definition && $ this ->definitionVariables ->contains ($ callable [0 ]))) {
698- return sprintf (" $ return { $ instantiation } %s->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
699+ return $ return . sprintf ("%s->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
699700 }
700701
701702 $ class = $ this ->dumpValue ($ callable [0 ]);
@@ -705,24 +706,24 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
705706 throw new RuntimeException (sprintf ('Cannot dump definition: The "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class? ' , $ id ));
706707 }
707708
708- return sprintf (" $ return { $ instantiation } %s::%s(%s); \n" , $ this ->dumpLiteralClass ($ class ), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
709+ return $ return . sprintf ("%s::%s(%s); \n" , $ this ->dumpLiteralClass ($ class ), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
709710 }
710711
711712 if (0 === strpos ($ class , 'new ' )) {
712- return sprintf (" $ return { $ instantiation } (%s)->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
713+ return $ return . sprintf ("(%s)->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
713714 }
714715
715- return sprintf (" $ return { $ instantiation } call_user_func(array(%s, '%s')%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? ', ' .implode (', ' , $ arguments ) : '' );
716+ return $ return . sprintf ("call_user_func(array(%s, '%s')%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? ', ' .implode (', ' , $ arguments ) : '' );
716717 }
717718
718- return sprintf (" $ return { $ instantiation } %s(%s); \n" , $ this ->dumpLiteralClass ($ this ->dumpValue ($ callable )), $ arguments ? implode (', ' , $ arguments ) : '' );
719+ return $ return . sprintf ("%s(%s); \n" , $ this ->dumpLiteralClass ($ this ->dumpValue ($ callable )), $ arguments ? implode (', ' , $ arguments ) : '' );
719720 }
720721
721722 if (false !== strpos ($ class , '$ ' )) {
722- return sprintf (" \$class = %s; \n\n $ return { $ instantiation } new \$class(%s); \n" , $ class , implode (', ' , $ arguments ));
723+ return sprintf (" \$class = %s; \n\n%snew \$class(%s); \n" , $ class, $ return , implode (', ' , $ arguments ));
723724 }
724725
725- return sprintf (" $ return { $ instantiation } new %s(%s); \n" , $ this ->dumpLiteralClass ($ class ), implode (', ' , $ arguments ));
726+ return $ return . sprintf ("new %s(%s); \n" , $ this ->dumpLiteralClass ($ class ), implode (', ' , $ arguments ));
726727 }
727728
728729 /**
@@ -890,7 +891,7 @@ private function addNormalizedIds()
890891 ksort ($ normalizedIds );
891892 foreach ($ normalizedIds as $ id => $ normalizedId ) {
892893 if ($ this ->container ->has ($ normalizedId )) {
893- $ code .= ' ' .$ this ->export ($ id ).' => ' .$ this ->export ($ normalizedId ).", \n" ;
894+ $ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ normalizedId ).", \n" ;
894895 }
895896 }
896897
@@ -912,7 +913,7 @@ private function addMethodMap()
912913 $ code = " \$this->methodMap = array( \n" ;
913914 ksort ($ definitions );
914915 foreach ($ definitions as $ id => $ definition ) {
915- $ code .= ' ' .$ this ->export ($ id ).' => ' .$ this ->export ($ this ->generateMethodName ($ id )).", \n" ;
916+ $ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ this ->generateMethodName ($ id )).", \n" ;
916917 }
917918
918919 return $ code ." ); \n" ;
@@ -933,7 +934,7 @@ private function addPrivateServices()
933934 ksort ($ definitions );
934935 foreach ($ definitions as $ id => $ definition ) {
935936 if (!$ definition ->isPublic ()) {
936- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
937+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
937938 }
938939 }
939940
@@ -966,7 +967,7 @@ private function addAliases()
966967 while (isset ($ aliases [$ id ])) {
967968 $ id = (string ) $ aliases [$ id ];
968969 }
969- $ code .= ' ' .$ this ->export ($ alias ).' => ' .$ this ->export ($ id ).", \n" ;
970+ $ code .= ' ' .$ this ->doExport ($ alias ).' => ' .$ this ->doExport ($ id ).", \n" ;
970971 }
971972
972973 return $ code ." ); \n" ;
@@ -1688,9 +1689,9 @@ private function exportTargetDirs()
16881689 private function export ($ value )
16891690 {
16901691 if (null !== $ this ->targetDirRegex && is_string ($ value ) && preg_match ($ this ->targetDirRegex , $ value , $ matches , PREG_OFFSET_CAPTURE )) {
1691- $ prefix = $ matches [0 ][1 ] ? $ this ->doExport (substr ($ value , 0 , $ matches [0 ][1 ])).'. ' : '' ;
1692+ $ prefix = $ matches [0 ][1 ] ? $ this ->doExport (substr ($ value , 0 , $ matches [0 ][1 ]), true ).'. ' : '' ;
16921693 $ suffix = $ matches [0 ][1 ] + strlen ($ matches [0 ][0 ]);
1693- $ suffix = isset ($ value [$ suffix ]) ? '. ' .$ this ->doExport (substr ($ value , $ suffix )) : '' ;
1694+ $ suffix = isset ($ value [$ suffix ]) ? '. ' .$ this ->doExport (substr ($ value , $ suffix ), true ) : '' ;
16941695 $ dirname = '__DIR__ ' ;
16951696
16961697 if (0 < $ offset = 1 + $ this ->targetDirMaxMatches - count ($ matches )) {
@@ -1704,10 +1705,10 @@ private function export($value)
17041705 return $ dirname ;
17051706 }
17061707
1707- return $ this ->doExport ($ value );
1708+ return $ this ->doExport ($ value, true );
17081709 }
17091710
1710- private function doExport ($ value )
1711+ private function doExport ($ value, $ resolveEnv = false )
17111712 {
17121713 if (is_string ($ value ) && false !== strpos ($ value , "\n" )) {
17131714 $ cleanParts = explode ("\n" , $ value );
@@ -1717,7 +1718,7 @@ private function doExport($value)
17171718 $ export = var_export ($ value , true );
17181719 }
17191720
1720- if ("' " === $ export [0 ] && $ export !== $ resolvedExport = $ this ->container ->resolveEnvPlaceholders ($ export , "'. \$this->getEnv('%s').' " )) {
1721+ if ($ resolveEnv && "' " === $ export [0 ] && $ export !== $ resolvedExport = $ this ->container ->resolveEnvPlaceholders ($ export , "'. \$this->getEnv('%s').' " )) {
17211722 $ export = $ resolvedExport ;
17221723 if ("' " === $ export [1 ]) {
17231724 $ export = substr ($ export , 3 );
0 commit comments