@@ -92,6 +92,7 @@ class PhpDumper extends Dumper
92
92
private $ locatedIds = [];
93
93
private $ serviceLocatorTag ;
94
94
private $ exportedVariables = [];
95
+ private $ dynamicParameters = [];
95
96
private $ baseClass ;
96
97
97
98
/**
@@ -141,6 +142,7 @@ public function dump(array $options = [])
141
142
$ this ->targetDirRegex = null ;
142
143
$ this ->inlinedRequires = [];
143
144
$ this ->exportedVariables = [];
145
+ $ this ->dynamicParameters = [];
144
146
$ options = array_merge ([
145
147
'class ' => 'ProjectServiceContainer ' ,
146
148
'base_class ' => 'Container ' ,
@@ -223,11 +225,12 @@ public function dump(array $options = [])
223
225
$ this ->preload = array_combine ($ options ['preload_classes ' ], $ options ['preload_classes ' ]);
224
226
}
225
227
228
+ $ code = $ this ->addDefaultParametersMethod ();
226
229
$ code =
227
230
$ this ->startClass ($ options ['class ' ], $ baseClass , $ this ->inlineFactories && $ proxyClasses ).
228
231
$ this ->addServices ($ services ).
229
232
$ this ->addDeprecatedAliases ().
230
- $ this -> addDefaultParametersMethod ()
233
+ $ code
231
234
;
232
235
233
236
$ proxyClasses = $ proxyClasses ?? $ this ->generateProxyClasses ();
@@ -391,6 +394,7 @@ class %s extends {$options['class']}
391
394
$ this ->circularReferences = [];
392
395
$ this ->locatedIds = [];
393
396
$ this ->exportedVariables = [];
397
+ $ this ->dynamicParameters = [];
394
398
$ this ->preload = [];
395
399
396
400
$ unusedEnvs = [];
@@ -1512,6 +1516,7 @@ private function addDefaultParametersMethod(): string
1512
1516
1513
1517
if ($ hasEnum || preg_match ("/ \\\$this->(?:getEnv\('(?:[-.\w]*+:)*+\w++'\)|targetDir\.'')/ " , $ export [1 ])) {
1514
1518
$ dynamicPhp [$ key ] = sprintf ('%scase %s: $value = %s; break; ' , $ export [0 ], $ this ->export ($ key ), $ export [1 ]);
1519
+ $ this ->dynamicParameters [$ key ] = true ;
1515
1520
} else {
1516
1521
$ php [] = sprintf ('%s%s => %s, ' , $ export [0 ], $ this ->export ($ key ), $ export [1 ]);
1517
1522
}
@@ -1916,20 +1921,18 @@ private function dumpLiteralClass(string $class): string
1916
1921
1917
1922
private function dumpParameter (string $ name ): string
1918
1923
{
1919
- if ($ this ->container ->hasParameter ($ name )) {
1920
- $ value = $ this ->container -> getParameter ($ name );
1921
- $ dumpedValue = $ this -> dumpValue ( $ value , false );
1924
+ if (! $ this ->container ->hasParameter ($ name) || ( $ this -> dynamicParameters [ $ name ] ?? false )) {
1925
+ return sprintf ( ' $this->getParameter(%s) ' , $ this -> doExport ($ name) );
1926
+ }
1922
1927
1923
- if (!$ value || !\is_array ($ value )) {
1924
- return $ dumpedValue ;
1925
- }
1928
+ $ value = $ this ->container ->getParameter ($ name );
1929
+ $ dumpedValue = $ this ->dumpValue ($ value , false );
1926
1930
1927
- if (!preg_match ("/ \\\$this->(?:getEnv\('(?:[-.\w]*+:)*+\w++'\)|targetDir\.'')/ " , $ dumpedValue )) {
1928
- return sprintf ('$this->parameters[%s] ' , $ this ->doExport ($ name ));
1929
- }
1931
+ if (!$ value || !\is_array ($ value )) {
1932
+ return $ dumpedValue ;
1930
1933
}
1931
1934
1932
- return sprintf ('$this->getParameter(%s) ' , $ this ->doExport ($ name ));
1935
+ return sprintf ('$this->parameters[%s] ' , $ this ->doExport ($ name ));
1933
1936
}
1934
1937
1935
1938
private function getServiceCall (string $ id , Reference $ reference = null ): string
0 commit comments