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,39 @@ 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.
664
+ * Set to "true" when you want to use the current ContainerBuilder
665
+ * directly, keep to "false" when the container is dumped instead.
660
666
*/
661
- public function compile ()
667
+ public function compile (/*$resolveEnvPlaceholders = false*/ )
662
668
{
669
+ if (1 <= func_num_args ()) {
670
+ $ resolveEnvPlaceholders = func_get_arg (0 );
671
+ } else {
672
+ if (__CLASS__ !== static ::class) {
673
+ $ r = new \ReflectionMethod ($ this , __FUNCTION__ );
674
+ if (__CLASS__ !== $ r ->getDeclaringClass ()->getName () && (1 > $ r ->getNumberOfParameters () || 'resolveEnvPlaceholders ' !== $ r ->getParameters ()[0 ]->name )) {
675
+ @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 );
676
+ }
677
+ }
678
+ $ resolveEnvPlaceholders = false ;
679
+ }
663
680
$ compiler = $ this ->getCompiler ();
664
681
665
682
if ($ this ->trackResources ) {
666
683
foreach ($ compiler ->getPassConfig ()->getPasses () as $ pass ) {
667
684
$ this ->addObjectResource ($ pass );
668
685
}
669
686
}
687
+ $ bag = $ this ->getParameterBag ();
688
+
689
+ if ($ resolveEnvPlaceholders && $ bag instanceof EnvPlaceholderParameterBag) {
690
+ $ this ->parameterBag = new ParameterBag ($ this ->resolveEnvPlaceholders ($ bag ->all (), true ));
691
+ $ this ->envPlaceholders = $ bag ->getEnvPlaceholders ();
692
+ $ this ->parameterBag = $ bag = new ParameterBag ($ this ->resolveEnvPlaceholders ($ this ->parameterBag ->all ()));
693
+ }
670
694
671
695
$ compiler ->compile ($ this );
672
696
@@ -680,7 +704,6 @@ public function compile()
680
704
}
681
705
682
706
$ this ->extensionConfigs = array ();
683
- $ bag = $ this ->getParameterBag ();
684
707
685
708
parent ::compile ();
686
709
0 commit comments