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 \ClassExistenceResource ;
29
30
use Symfony \Component \Config \Resource \DirectoryResource ;
30
31
use Symfony \Component \Config \Resource \FileExistenceResource ;
@@ -657,16 +658,37 @@ public function prependExtensionConfig($name, array $config)
657
658
* * Parameter values are resolved;
658
659
* * The parameter bag is frozen;
659
660
* * Extension loading is disabled.
661
+ *
662
+ * @param bool $resolveEnvPlaceholders Whether %env()% parameters should be resolved using the current
663
+ * env vars or be replaced by uniquely identifiable placeholders
660
664
*/
661
- public function compile ()
665
+ public function compile (/*$resolveEnvPlaceholders = false*/ )
662
666
{
667
+ if (1 <= func_num_args ()) {
668
+ $ resolveEnvPlaceholders = func_get_arg (0 );
669
+ } else {
670
+ if (__CLASS__ !== static ::class) {
671
+ $ r = new \ReflectionMethod ($ this , __FUNCTION__ );
672
+ if (__CLASS__ !== $ r ->getDeclaringClass ()->getName () && (1 > $ r ->getNumberOfParameters () || 'resolveEnvPlaceholders ' !== $ r ->getParameters ()[0 ]->name )) {
673
+ @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 );
674
+ }
675
+ }
676
+ $ resolveEnvPlaceholders = false ;
677
+ }
663
678
$ compiler = $ this ->getCompiler ();
664
679
665
680
if ($ this ->trackResources ) {
666
681
foreach ($ compiler ->getPassConfig ()->getPasses () as $ pass ) {
667
682
$ this ->addObjectResource ($ pass );
668
683
}
669
684
}
685
+ $ bag = $ this ->getParameterBag ();
686
+
687
+ if ($ resolveEnvPlaceholders && $ bag instanceof EnvPlaceholderParameterBag) {
688
+ $ this ->parameterBag = new ParameterBag ($ this ->resolveEnvPlaceholders ($ bag ->all (), true ));
689
+ $ this ->envPlaceholders = $ bag ->getEnvPlaceholders ();
690
+ $ this ->parameterBag = $ bag = new ParameterBag ($ this ->resolveEnvPlaceholders ($ this ->parameterBag ->all ()));
691
+ }
670
692
671
693
$ compiler ->compile ($ this );
672
694
@@ -680,7 +702,6 @@ public function compile()
680
702
}
681
703
682
704
$ this ->extensionConfigs = array ();
683
- $ bag = $ this ->getParameterBag ();
684
705
685
706
parent ::compile ();
686
707
0 commit comments