@@ -192,7 +192,7 @@ public function dump(array $options = array())
192192 sort ($ ids );
193193 $ c = "<?php \n\nreturn array( \n" ;
194194 foreach ($ ids as $ id ) {
195- $ c .= ' ' .$ this ->export ($ id )." => true, \n" ;
195+ $ c .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
196196 }
197197 $ files ['removed-ids.php ' ] = $ c .= "); \n" ;
198198 }
@@ -894,6 +894,7 @@ private function generateServiceFiles()
894894 private function addNewInstance (Definition $ definition , $ return , $ instantiation , $ id )
895895 {
896896 $ class = $ this ->dumpValue ($ definition ->getClass ());
897+ $ return = ' ' .$ return .$ instantiation ;
897898
898899 $ arguments = array ();
899900 foreach ($ definition ->getArguments () as $ value ) {
@@ -909,7 +910,7 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
909910
910911 if ($ callable [0 ] instanceof Reference
911912 || ($ callable [0 ] instanceof Definition && $ this ->definitionVariables ->contains ($ callable [0 ]))) {
912- return sprintf (" $ return { $ instantiation } %s->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
913+ return $ return . sprintf ("%s->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
913914 }
914915
915916 $ class = $ this ->dumpValue ($ callable [0 ]);
@@ -919,24 +920,24 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
919920 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 ));
920921 }
921922
922- return sprintf (" $ return { $ instantiation } %s::%s(%s); \n" , $ this ->dumpLiteralClass ($ class ), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
923+ return $ return . sprintf ("%s::%s(%s); \n" , $ this ->dumpLiteralClass ($ class ), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
923924 }
924925
925926 if (0 === strpos ($ class , 'new ' )) {
926- return sprintf (" $ return { $ instantiation } (%s)->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
927+ return $ return . sprintf ("(%s)->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
927928 }
928929
929- return sprintf (" $ return { $ instantiation } call_user_func(array(%s, '%s')%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? ', ' .implode (', ' , $ arguments ) : '' );
930+ return $ return . sprintf ("call_user_func(array(%s, '%s')%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? ', ' .implode (', ' , $ arguments ) : '' );
930931 }
931932
932- return sprintf (" $ return { $ instantiation } %s(%s); \n" , $ this ->dumpLiteralClass ($ this ->dumpValue ($ callable )), $ arguments ? implode (', ' , $ arguments ) : '' );
933+ return $ return . sprintf ("%s(%s); \n" , $ this ->dumpLiteralClass ($ this ->dumpValue ($ callable )), $ arguments ? implode (', ' , $ arguments ) : '' );
933934 }
934935
935936 if (false !== strpos ($ class , '$ ' )) {
936- return sprintf (" \$class = %s; \n\n $ return { $ instantiation } new \$class(%s); \n" , $ class , implode (', ' , $ arguments ));
937+ return sprintf (" \$class = %s; \n\n%snew \$class(%s); \n" , $ class, $ return , implode (', ' , $ arguments ));
937938 }
938939
939- return sprintf (" $ return { $ instantiation } new %s(%s); \n" , $ this ->dumpLiteralClass ($ class ), implode (', ' , $ arguments ));
940+ return $ return . sprintf ("new %s(%s); \n" , $ this ->dumpLiteralClass ($ class ), implode (', ' , $ arguments ));
940941 }
941942
942943 /**
@@ -1087,7 +1088,7 @@ private function addNormalizedIds()
10871088 ksort ($ normalizedIds );
10881089 foreach ($ normalizedIds as $ id => $ normalizedId ) {
10891090 if ($ this ->container ->has ($ normalizedId )) {
1090- $ code .= ' ' .$ this ->export ($ id ).' => ' .$ this ->export ($ normalizedId ).", \n" ;
1091+ $ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ normalizedId ).", \n" ;
10911092 }
10921093 }
10931094
@@ -1106,7 +1107,7 @@ private function addSyntheticIds()
11061107 ksort ($ definitions );
11071108 foreach ($ definitions as $ id => $ definition ) {
11081109 if ($ definition ->isSynthetic () && 'service_container ' !== $ id ) {
1109- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
1110+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
11101111 }
11111112 }
11121113
@@ -1130,7 +1131,7 @@ private function addRemovedIds()
11301131 $ ids = array_keys ($ ids );
11311132 sort ($ ids );
11321133 foreach ($ ids as $ id ) {
1133- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
1134+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
11341135 }
11351136
11361137 $ code = "array( \n{$ code } ) " ;
@@ -1158,7 +1159,7 @@ private function addMethodMap()
11581159 ksort ($ definitions );
11591160 foreach ($ definitions as $ id => $ definition ) {
11601161 if (!$ definition ->isSynthetic () && (!$ this ->asFiles || !$ definition ->isShared () || $ this ->isHotPath ($ definition ))) {
1161- $ code .= ' ' .$ this ->export ($ id ).' => ' .$ this ->export ($ this ->generateMethodName ($ id )).", \n" ;
1162+ $ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ this ->generateMethodName ($ id )).", \n" ;
11621163 }
11631164 }
11641165
@@ -1177,7 +1178,7 @@ private function addFileMap()
11771178 ksort ($ definitions );
11781179 foreach ($ definitions as $ id => $ definition ) {
11791180 if (!$ definition ->isSynthetic () && $ definition ->isShared () && !$ this ->isHotPath ($ definition )) {
1180- $ code .= sprintf (" %s => __DIR__.'/%s.php', \n" , $ this ->export ($ id ), $ this ->generateMethodName ($ id ));
1181+ $ code .= sprintf (" %s => __DIR__.'/%s.php', \n" , $ this ->doExport ($ id ), $ this ->generateMethodName ($ id ));
11811182 }
11821183 }
11831184
@@ -1197,15 +1198,15 @@ private function addPrivateServices()
11971198 ksort ($ aliases );
11981199 foreach ($ aliases as $ id => $ alias ) {
11991200 if ($ alias ->isPrivate ()) {
1200- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
1201+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
12011202 }
12021203 }
12031204
12041205 $ definitions = $ this ->container ->getDefinitions ();
12051206 ksort ($ definitions );
12061207 foreach ($ definitions as $ id => $ definition ) {
12071208 if (!$ definition ->isPublic ()) {
1208- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
1209+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
12091210 }
12101211 }
12111212
@@ -1238,7 +1239,7 @@ private function addAliases()
12381239 while (isset ($ aliases [$ id ])) {
12391240 $ id = (string ) $ aliases [$ id ];
12401241 }
1241- $ code .= ' ' .$ this ->export ($ alias ).' => ' .$ this ->export ($ id ).", \n" ;
1242+ $ code .= ' ' .$ this ->doExport ($ alias ).' => ' .$ this ->doExport ($ id ).", \n" ;
12421243 }
12431244
12441245 return $ code ." ); \n" ;
@@ -2037,9 +2038,9 @@ private function isHotPath(Definition $definition)
20372038 private function export ($ value )
20382039 {
20392040 if (null !== $ this ->targetDirRegex && is_string ($ value ) && preg_match ($ this ->targetDirRegex , $ value , $ matches , PREG_OFFSET_CAPTURE )) {
2040- $ prefix = $ matches [0 ][1 ] ? $ this ->doExport (substr ($ value , 0 , $ matches [0 ][1 ])).'. ' : '' ;
2041+ $ prefix = $ matches [0 ][1 ] ? $ this ->doExport (substr ($ value , 0 , $ matches [0 ][1 ]), true ).'. ' : '' ;
20412042 $ suffix = $ matches [0 ][1 ] + strlen ($ matches [0 ][0 ]);
2042- $ suffix = isset ($ value [$ suffix ]) ? '. ' .$ this ->doExport (substr ($ value , $ suffix )) : '' ;
2043+ $ suffix = isset ($ value [$ suffix ]) ? '. ' .$ this ->doExport (substr ($ value , $ suffix ), true ) : '' ;
20432044 $ dirname = '__DIR__ ' ;
20442045 $ offset = 1 + $ this ->targetDirMaxMatches - count ($ matches );
20452046
@@ -2054,10 +2055,10 @@ private function export($value)
20542055 return $ dirname ;
20552056 }
20562057
2057- return $ this ->doExport ($ value );
2058+ return $ this ->doExport ($ value, true );
20582059 }
20592060
2060- private function doExport ($ value )
2061+ private function doExport ($ value, $ resolveEnv = false )
20612062 {
20622063 if (is_string ($ value ) && false !== strpos ($ value , "\n" )) {
20632064 $ cleanParts = explode ("\n" , $ value );
@@ -2067,7 +2068,7 @@ private function doExport($value)
20672068 $ export = var_export ($ value , true );
20682069 }
20692070
2070- if ("' " === $ export [0 ] && $ export !== $ resolvedExport = $ this ->container ->resolveEnvPlaceholders ($ export , "'. \$this->getEnv('string:%s').' " )) {
2071+ if ($ resolveEnv && "' " === $ export [0 ] && $ export !== $ resolvedExport = $ this ->container ->resolveEnvPlaceholders ($ export , "'. \$this->getEnv('string:%s').' " )) {
20712072 $ export = $ resolvedExport ;
20722073 if (".'' " === substr ($ export , -3 )) {
20732074 $ export = substr ($ export , 0 , -3 );
0 commit comments