@@ -192,7 +192,7 @@ public function dump(array $options = array())
192
192
sort ($ ids );
193
193
$ c = "<?php \n\nreturn array( \n" ;
194
194
foreach ($ ids as $ id ) {
195
- $ c .= ' ' .$ this ->export ($ id )." => true, \n" ;
195
+ $ c .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
196
196
}
197
197
$ files ['removed-ids.php ' ] = $ c .= "); \n" ;
198
198
}
@@ -894,6 +894,7 @@ private function generateServiceFiles()
894
894
private function addNewInstance (Definition $ definition , $ return , $ instantiation , $ id )
895
895
{
896
896
$ class = $ this ->dumpValue ($ definition ->getClass ());
897
+ $ return = ' ' .$ return .$ instantiation ;
897
898
898
899
$ arguments = array ();
899
900
foreach ($ definition ->getArguments () as $ value ) {
@@ -909,7 +910,7 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
909
910
910
911
F438
if ($ callable [0 ] instanceof Reference
911
912
|| ($ 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 ) : '' );
913
914
}
914
915
915
916
$ class = $ this ->dumpValue ($ callable [0 ]);
@@ -919,24 +920,24 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
919
920
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 ));
920
921
}
921
922
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 ) : '' );
923
924
}
924
925
925
926
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 ) : '' );
927
928
}
928
929
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 ) : '' );
930
931
}
931
932
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 ) : '' );
933
934
}
934
935
935
936
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 ));
937
938
}
938
939
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 ));
940
941
}
941
942
942
943
/**
@@ -1087,7 +1088,7 @@ private function addNormalizedIds()
1087
1088
ksort ($ normalizedIds );
1088
1089
foreach ($ normalizedIds as $ id => $ normalizedId ) {
1089
1090
if ($ this ->container ->has ($ normalizedId )) {
1090
- $ code .= ' ' .$ this ->export ($ id ).' => ' .$ this ->export ($ normalizedId ).", \n" ;
1091
+ $ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ normalizedId ).", \n" ;
1091
1092
}
1092
1093
}
1093
1094
@@ -1106,7 +1107,7 @@ private function addSyntheticIds()
1106
1107
ksort ($ definitions );
1107
1108
foreach ($ definitions as $ id => $ definition ) {
1108
1109
if ($ definition ->isSynthetic () && 'service_container ' !== $ id ) {
1109
- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
1110
+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
1110
1111
}
1111
1112
}
1112
1113
@@ -1130,7 +1131,7 @@ private function addRemovedIds()
1130
1131
$ ids = array_keys ($ ids );
1131
1132
sort ($ ids );
1132
1133
foreach ($ ids as $ id ) {
1133
- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
1134
+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
1134
1135
}
1135
1136
1136
1137
$ code = "array( \n{$ code } ) " ;
@@ -1158,7 +1159,7 @@ private function addMethodMap()
1158
1159
ksort ($ definitions );
1159
1160
foreach ($ definitions as $ id => $ definition ) {
1160
1161
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" ;
1162
1163
}
1163
1164
}
1164
1165
@@ -1177,7 +1178,7 @@ private function addFileMap()
1177
1178
ksort ($ definitions );
1178
1179
foreach ($ definitions as $ id => $ definition ) {
1179
1180
if (!$ definition ->isSynthetic () && $ definition ->isShared () && !$ this ->isHotPath ($ definition )) {
1180
- $ code .= sprintf (" %s => __DIR__.'/%s.php', \n" , $ this<
10000
/span> ->export ($ id ), $ this ->generateMethodName ($ id ));
1181
+ $ code .= sprintf (" %s => __DIR__.'/%s.php', \n" , $ this ->doExport ($ id ), $ this ->generateMethodName ($ id ));
1181
1182
}
1182
1183
}
1183
1184
@@ -1197,15 +1198,15 @@ private function addPrivateServices()
1197
1198
ksort ($ aliases );
1198
1199
foreach ($ aliases as $ id => $ alias ) {
1199
1200
if ($ alias ->isPrivate ()) {
1200
- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
1201
+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
1201
1202
}
1202
1203
}
1203
1204
1204
1205
$ definitions = $ this ->container ->getDefinitions ();
1205
1206
ksort ($ definitions );
1206
1207
foreach ($ definitions as $ id => $ definition ) {
1207
1208
if (!$ definition ->isPublic ()) {
1208
- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
1209
+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
1209
1210
}
1210
1211
}
1211
1212
@@ -1238,7 +1239,7 @@ private function addAliases()
1238
1239
while (isset ($ aliases [$ id ])) {
1239
1240
$ id = (string ) $ aliases [$ id ];
1240
1241
}
1241
- $ code .= ' ' .$ this ->export ($ alias ).' => ' .$ this ->export ($ id ).", \n" ;
1242
+ $ code .= ' ' .$ this ->doExport ($ alias ).' => ' .$ this ->doExport ($ id ).", \n" ;
1242
1243
}
1243
1244
1244
1245
return $ code ." ); \n" ;
@@ -2037,9 +2038,9 @@ private function isHotPath(Definition $definition)
2037
2038
private function export ($ value )
2038
2039
{
2039
2040
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 ).'. ' : '' ;
2041
2042
$ 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 ) : '' ;
2043
2044
$ dirname = '__DIR__ ' ;
2044
2045
$ offset = 1 + $ this ->targetDirMaxMatches - count ($ matches );
2045
2046
@@ -2054,10 +2055,10 @@ private function export($value)
2054
2055
return $ dirname ;
2055
2056
}
2056
2057
2057
- return $ this ->doExport ($ value );
2058
+ return $ this ->doExport ($ value, true );
2058
2059
}
2059
2060
2060
- private function doExport ($ value )
2061
+ private function doExport ($ value, $ resolveEnv = false )
2061
2062
{
2062
2063
if (is_string ($ value ) && false !== strpos ($ value , "\n" )) {
2063
2064
$ cleanParts = explode ("\n" , $ value );
@@ -2067,7 +2068,7 @@ private function doExport($value)
2067
2068
$ export = var_export ($ value , true );
2068
2069
}
2069
2070
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').' " )) {
2071
2072
$ export = $ resolvedExport ;
2072
2073
if (".'' " === substr ($ export , -3 )) {
2073
2074
$ export = substr ($ export , 0 , -3 );
0 commit comments