13
13
14
14
use Symfony \Component \DependencyInjection \ContainerBuilder ;
15
15
use Symfony \Component \DependencyInjection \Extension \ConfigurationExtensionInterface ;
16
+ use Symfony \Component \DependencyInjection \Extension \Extension ;
16
17
use Symfony \Component \DependencyInjection \Extension \PrependExtensionInterface ;
18
+ use Symfony \Component \DependencyInjection \Parameterbag \EnvPlaceholderParameterBag ;
17
19
18
20
/**
19
21
* Merges extension configs into the container builder.
@@ -43,7 +45,8 @@ public function process(ContainerBuilder $container)
43
45
// this extension was not called
44
46
continue ;
45
47
}
46
- $ config = $ container ->getParameterBag ()->resolveValue ($ config );
48
+ $ resolvingBag = clone $ container ->getParameterBag ();
49
+ $ config = $ resolvingBag ->resolveValue ($ config );
47
50
48
51
$ tmpContainer = new ContainerBuilder ($ container ->getParameterBag ());
49
52
$ tmpContainer ->setResourceTracking ($ container ->isTrackingResources ());
@@ -58,6 +61,11 @@ public function process(ContainerBuilder $container)
58
61
59
62
$ extension ->load ($ config , $ tmpContainer );
60
63
64
+ if ($ extension instanceof Extension && $ resolvingBag instanceof EnvPlaceholderParameterBag) {
65
+ $ resolvingBag = new MergeExtensionConfigurationParameterBag ($ extension ->getProcessedConfigs (), $ resolvingBag );
66
+ $ container ->getParameterBag ()->mergeEnvPlaceholders ($ resolvingBag );
67
+ }
68
+
61
69
$ container ->merge ($ tmpContainer );
62
70
$ container ->getParameterBag ()->add ($ parameters );
63
71
}
@@ -66,3 +74,53 @@ public function process(ContainerBuilder $container)
66
74
$ container ->addAliases ($ aliases );
67
75
}
68
76
}
77
+
78
+ /**
79
+ * @internal
80
+ */
81
+ class MergeExtensionConfigurationParameterBag extends EnvPlaceholderParameterBag
82
+ {
83
+ private $ envPlaceholders ;
84
+
85
+ public function __construct (array $ config , parent $ resolvingBag )
86
+ {
87
+ $ this ->envPlaceholders = $ resolvingBag ->getEnvPlaceholders ();
88
+ $ config = $ this ->resolveEnvPlaceholders ($ config );
89
+ parent ::__construct ($ this ->resolveEnvReferences ($ config ));
90
+ }
91
+
92
+ /**
93
+ * {@inheritdoc}
94
+ */
95
+ public function getEnvPlaceholders ()
96
+ {
97
+ $ envPlaceholders = parent ::getEnvPlaceholders ();
98
+
99
+ foreach ($ envPlaceholders as $ env => $ placeholders ) {
100
+ if (isset ($ this ->envPlaceholders [$ env ])) {
101
+ $ envPlaceholders [$ env ] += $ this ->envPlaceholders [$ env ];
102
+ }
103
+ }
104
+
105
+ return $ envPlaceholders ;
106
+ }
107
+
108
+ private function resolveEnvPlaceholders ($ value )
109
+ {
110
+ if (is_array ($ value )) {
111
+ foreach ($ value as $ k => $ v ) {
112
+ $ value [$ this ->resolveEnvPlaceholders ($ k )] = $ this ->resolveEnvPlaceholders ($ v );
113
+ }
114
+ } elseif (is_string ($ value )) {
115
+ foreach ($ this ->envPlaceholders as $ env => $ placeholders ) {
116
+ foreach ($ placeholders as $ placeholder ) {
117
+ if (false !== stripos ($ value , $ placeholder )) {
118
+ $ value = str_ireplace ($ placeholder , "%env( $ env)% " , $ value );
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ return $ value ;
125
+ }
126
+ }
0 commit comments