25
25
use Symfony \Component \DependencyInjection \Exception \ServiceNotFoundException ;
26
26
use Symfony \Component \DependencyInjection \Extension \ExtensionInterface ;
27
27
use Symfony \Component \DependencyInjection \ParameterBag \EnvPlaceholderParameterBag ;
28
+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
28
29
use Symfony \Component \Config \Resource \FileResource ;
29
30
use Symfony \Component \Config \Resource \ResourceInterface ;
30
31
use Symfony \Component \DependencyInjection \LazyProxy \Instantiator \InstantiatorInterface ;
@@ -555,16 +556,37 @@ public function prependExtensionConfig($name, array $config)
555
556
* * Parameter values are resolved;
556
557
* * The parameter bag is frozen;
557
558
* * Extension loading is disabled.
559
+ *
560
+ * @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved using the current
561
+ * env vars or be replaced by uniquely identifiable placeholders
558
562
*/
559
- public function compile ()
563
+ public function compile (/*$resolveEnvPlaceholders = false*/ )
560
564
{
565
+ if (1 <= func_num_args ()) {
566
+ $ resolveEnvPlaceholders = func_get_arg (0 );
567
+ } else {
568
+ if (__CLASS__ !== static ::class) {
569
+ $ r = new \ReflectionMethod ($ this , __FUNCTION__ );
570
+ if (__CLASS__ !== $ r ->getDeclaringClass ()->getName () && (1 > $ r ->getNumberOfParameters () || 'resolveEnvPlaceholders ' !== $ r ->getParameters ()[0 ]->name )) {
571
+ @trigger_error (sprintf ('The %s::compile() method expects a first "$resolveEnvPlaceholders" argument since version 3.3. It will be made mandatory in 4.0. ' , static ::class), E_USER_DEPRECATED );
572
+ }
573
+ }
574
+ $ resolveEnvPlaceholders = false ;
575
+ }
561
576
$ compiler = $ this ->getCompiler ();
562
577
563
578
if ($ this ->trackResources ) {
564
579
foreach ($ compiler ->getPassConfig ()->getPasses () as $ pass ) {
565
580
$ this ->addObjectResource ($ pass );
566
581
}
567
582
}
583
+ $ bag = $ this ->getParameterBag ();
584
+
585
+ if ($ resolveEnvPlaceholders && $ bag instanceof EnvPlaceholderParameterBag) {
586
+ $ this ->parameterBag = new ParameterBag ($ this ->resolveEnvPlaceholders ($ bag ->all (), true ));
587
+ $ this ->envPlaceholders = $ bag ->getEnvPlaceholders ();
588
+ $ this ->parameterBag = $ bag = new ParameterBag ($ this ->resolveEnvPlaceholders ($ this ->parameterBag ->all ()));
589
+ }
568
590
569
591
$ compiler ->compile ($ this );
570
592
@@ -578,7 +600,6 @@ public function compile()
578
600
}
579
601
580
602
$ this ->extensionConfigs = array ();
581
- $ bag = $ this ->getParameterBag ();
582
603
583
604
parent ::compile ();
584
605
0 commit comments