2525use Symfony \Component \DependencyInjection \Exception \ServiceNotFoundException ;
2626use Symfony \Component \DependencyInjection \Extension \ExtensionInterface ;
2727use Symfony \Component \DependencyInjection \ParameterBag \EnvPlaceholderParameterBag ;
28+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
2829use Symfony \Component \Config \Resource \ClassExistenceResource ;
2930use Symfony \Component \Config \Resource \DirectoryResource ;
3031use Symfony \Component \Config \Resource \FileExistenceResource ;
@@ -657,16 +658,37 @@ public function prependExtensionConfig($name, array $config)
657658 * * Parameter values are resolved;
658659 * * The parameter bag is frozen;
659660 * * 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
660664 */
661- public function compile ()
665+ public function compile (/*$resolveEnvPlaceholders = false*/ )
662666 {
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+ }
663678 $ compiler = $ this ->getCompiler ();
664679
665680 if ($ this ->trackResources ) {
666681 foreach ($ compiler ->getPassConfig ()->getPasses () as $ pass ) {
667682 $ this ->addObjectResource ($ pass );
668683 }
669684 }
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+ }
670692
671693 $ compiler ->compile ($ this );
672694
@@ -680,7 +702,6 @@ public function compile()
680702 }
681703
682704 $ this ->extensionConfigs = array ();
683- $ bag = $ this ->getParameterBag ();
684705
685706 parent ::compile ();
686707
0 commit comments