@@ -51,6 +51,11 @@ class DeploymentConfig
51
51
*/
52
52
private $ overrideData ;
53
53
54
+ /**
55
+ * @var array
56
+ */
57
+ private $ envOverrides = [];
58
+
54
59
/**
55
60
* Constructor
56
61
*
@@ -76,6 +81,7 @@ public function __construct(DeploymentConfig\Reader $reader, $overrideData = [])
76
81
*/
77
82
public function get ($ key = null , $ defaultValue = null )
78
83
{
84
+ //if no key is requested, then all config is returned.
79
85
if ($ key === null ) {
80
86
if (empty ($ this ->flatData )) {
81
87
$ this ->reloadData ();
@@ -84,7 +90,7 @@ public function get($key = null, $defaultValue = null)
84
90
}
85
91
$ result = $ this ->getByKey ($ key );
86
92
if ($ result === null ) {
87
- if (empty ($ this ->flatData )) {
93
+ if (empty ($ this ->flatData ) || count ( $ this -> getAllEnvOverrides ()) ) {
88
94
$ this ->reloadData ();
89
95
}
90
96
$ result = $ this ->getByKey ($ key );
@@ -181,19 +187,29 @@ private function reloadData(): void
181
187
);
182
188
// flatten data for config retrieval using get()
183
189
$ this ->flatData = $ this ->flattenParams ($ this ->data );
190
+ $ this ->flatData = $ this ->getAllEnvOverrides () + $ this ->flatData ;
191
+ }
184
192
185
- // allow reading values from env variables by convention
186
- // MAGENTO_DC_{path}, like db/connection/default/host =>
187
- // can be overwritten by MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST
188
- foreach (getenv () as $ key => $ value ) {
189
- if (false !== \strpos ($ key , self ::MAGENTO_ENV_PREFIX )
190
- && $ key !== self ::OVERRIDE_KEY
191
- ) {
192
- // convert MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST into db/connection/default/host
193
- $ flatKey = strtolower (str_replace ([self ::MAGENTO_ENV_PREFIX , '__ ' ], ['' , '/ ' ], $ key ));
194
- $ this ->flatData [$ flatKey ] = $ value ;
193
+ /**
194
+ * @return array
195
+ */
196
+ private function getAllEnvOverrides (): array
197
+ {
198
+ if (empty ($ this ->envOverrides )) {
199
+ // allow reading values from env variables by convention
200
+ // MAGENTO_DC_{path}, like db/connection/default/host =>
201
+ // can be overwritten by MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST
202
+ foreach (getenv () as $ key => $ value ) {
203
+ if (false !== \strpos ($ key , self ::MAGENTO_ENV_PREFIX )
204
+ && $ key !== self ::OVERRIDE_KEY
205
+ ) {
206
+ // convert MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST into db/connection/default/host
207
+ $ flatKey = strtolower (str_replace ([self ::MAGENTO_ENV_PREFIX , '__ ' ], ['' , '/ ' ], $ key ));
208
+ $ this ->envOverrides [$ flatKey ] = $ value ;
209
+ }
195
210
}
196
211
}
212
+ return $ this ->envOverrides ;
197
213
}
198
214
199
215
/**
0 commit comments