@@ -92,6 +92,7 @@ class PhpDumper extends Dumper
9292 private $ locatedIds = [];
9393 private $ serviceLocatorTag ;
9494 private $ exportedVariables = [];
95+ private $ dynamicParameters = [];
9596 private $ baseClass ;
9697
9798 /**
@@ -141,6 +142,7 @@ public function dump(array $options = [])
141142 $ this ->targetDirRegex = null ;
142143 $ this ->inlinedRequires = [];
143144 $ this ->exportedVariables = [];
145+ $ this ->dynamicParameters = [];
144146 $ options = array_merge ([
145147 'class ' => 'ProjectServiceContainer ' ,
146148 'base_class ' => 'Container ' ,
@@ -223,11 +225,12 @@ public function dump(array $options = [])
223225 $ this ->preload = array_combine ($ options ['preload_classes ' ], $ options ['preload_classes ' ]);
224226 }
225227
228+ $ code = $ this ->addDefaultParametersMethod ();
226229 $ code =
227230 $ this ->startClass ($ options ['class ' ], $ baseClass , $ this ->inlineFactories && $ proxyClasses ).
228231 $ this ->addServices ($ services ).
229232 $ this ->addDeprecatedAliases ().
230- $ this -> addDefaultParametersMethod ()
233+ $ code
231234 ;
232235
233236 $ proxyClasses = $ proxyClasses ?? $ this ->generateProxyClasses ();
@@ -391,6 +394,7 @@ class %s extends {$options['class']}
391394 $ this ->circularReferences = [];
392395 $ this ->locatedIds = [];
393396 $ this ->exportedVariables = [];
397+ $ this ->dynamicParameters = [];
394398 $ this ->preload = [];
395399
396400 $ unusedEnvs = [];
@@ -1512,6 +1516,7 @@ private function addDefaultParametersMethod(): string
15121516
15131517 if ($ hasEnum || preg_match ("/ \\\$this->(?:getEnv\('(?:[-.\w]*+:)*+\w++'\)|targetDir\.'')/ " , $ export [1 ])) {
15141518 $ dynamicPhp [$ key ] = sprintf ('%scase %s: $value = %s; break; ' , $ export [0 ], $ this ->export ($ key ), $ export [1 ]);
1519+ $ this ->dynamicParameters [$ key ] = true ;
15151520 } else {
15161521 $ php [] = sprintf ('%s%s => %s, ' , $ export [0 ], $ this ->export ($ key ), $ export [1 ]);
15171522 }
@@ -1916,20 +1921,18 @@ private function dumpLiteralClass(string $class): string
19161921
19171922 private function dumpParameter (string $ name ): string
19181923 {
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+ }
19221927
1923- if (!$ value || !\is_array ($ value )) {
1924- return $ dumpedValue ;
1925- }
1928+ $ value = $ this ->container ->getParameter ($ name );
1929+ $ dumpedValue = $ this ->dumpValue ($ value , false );
19261930
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 ;
19301933 }
19311934
1932- return sprintf ('$this->getParameter(%s) ' , $ this ->doExport ($ name ));
1935+ return sprintf ('$this->parameters[%s] ' , $ this ->doExport ($ name ));
19331936 }
19341937
19351938 private function getServiceCall (string $ id , Reference $ reference = null ): string
0 commit comments