@@ -88,6 +88,7 @@ class PhpDumper extends Dumper
88
88
private array $ locatedIds = [];
89
89
private string $ serviceLocatorTag ;
90
90
private array $ exportedVariables = [];
91
+ private array $ dynamicParameters = [];
91
92
private string $ baseClass ;
92
93
private string $ class ;
93
94
private DumperInterface $ proxyDumper ;
@@ -131,6 +132,7 @@ public function dump(array $options = []): string|array
131
132
$ this ->targetDirRegex = null ;
132
133
$ this ->inlinedRequires = [];
133
134
$ this ->exportedVariables = [];
135
+ $ this ->dynamicParameters = [];
134
136
$ options = array_merge ([
135
137
'class ' => 'ProjectServiceContainer ' ,
136
138
'base_class ' => 'Container ' ,
@@ -206,11 +208,12 @@ public function dump(array $options = []): string|array
206
208
$ this ->preload = array_combine ($ options ['preload_classes ' ], $ options ['preload_classes ' ]);
207
209
}
208
210
211
+ $ code = $ this ->addDefaultParametersMethod ();
209
212
$ code =
210
213
$ this ->startClass ($ options ['class ' ], $ baseClass , $ this ->inlineFactories && $ proxyClasses ).
211
214
$ this ->addServices ($ services ).
212
215
$ this ->addDeprecatedAliases ().
213
- $ this -> addDefaultParametersMethod ()
216
+ $ code
214
217
;
215
218
216
219
$ proxyClasses ??= $ this ->generateProxyClasses ();
@@ -374,6 +377,7 @@ class %s extends {$options['class']}
374
377
$ this ->circularReferences = [];
375
378
$ this ->locatedIds = [];
376
379
$ this ->exportedVariables = [];
380
+ $ this ->dynamicParameters = [];
377
381
$ this ->preload = [];
378
382
379
383
$ unusedEnvs = [];
@@ -1519,6 +1523,7 @@ private function addDefaultParametersMethod(): string
1519
1523
1520
1524
if ($ hasEnum || preg_match ("/ \\\$this->(?:getEnv\('(?:[-.\w \\\\]*+:)*+\w++'\)|targetDir\.'')/ " , $ export [1 ])) {
1521
1525
$ dynamicPhp [$ key ] = sprintf ('%s%s => %s, ' , $ export [0 ], $ this ->export ($ key ), $ export [1 ]);
1526
+ $ this ->dynamicParameters [$ key ] = true ;
1522
1527
} else {
1523
1528
$ php [] = sprintf ('%s%s => %s, ' , $ export [0 ], $ this ->export ($ key ), $ export [1 ]);
1524
1529
}
@@ -1917,20 +1922,18 @@ private function dumpLiteralClass(string $class): string
1917
1922
1918
1923
private function dumpParameter (string $ name ): string
1919
1924
{
1920
- if ($ this ->container ->hasParameter ($ name )) {
1921
- $ value = $ this ->container -> getParameter ($ name );
1922
- $ dumpedValue = $ this -> dumpValue ( $ value , false );
1925
+ if (! $ this ->container ->hasParameter ($ name) || ( $ this -> dynamicParameters [ $ name ] ?? false )) {
1926
+ return sprintf ( ' $this->getParameter(%s) ' , $ this -> doExport ($ name) );
1927
+ }
1923
1928
1924
- if (!$ value || !\is_array ($ value )) {
1925
- return $ dumpedValue ;
1926
- }
1929
+ $ value = $ this ->container ->getParameter ($ name );
1930
+ $ dumpedValue = $ this ->dumpValue ($ value , false );
1927
1931
1928
- if (!preg_match ("/ \\\$this->(?:getEnv\('(?:[-.\w \\\\]*+:)*+\w++'\)|targetDir\.'')/ " , $ dumpedValue )) {
1929
- return sprintf ('$this->parameters[%s] ' , $ this ->doExport ($ name ));
1930
- }
1932
+ if (!$ value || !\is_array ($ value )) {
1933
+ return $ dumpedValue ;
1931
1934
}
1932
1935
1933
- return sprintf ('$this->getParameter(%s) ' , $ this ->doExport ($ name ));
1936
+ return sprintf ('$this->parameters[%s] ' , $ this ->doExport ($ name ));
1934
1937
}
1935
1938
1936
1939
private function getServiceCall (string $ id , Reference $ reference = null ): string
0 commit comments