@@ -51,6 +51,11 @@ class DeploymentConfig
5151 */
5252 private $ overrideData ;
5353
54+ /**
55+ * @var array
56+ */
57+ private $ envOverrides = [];
58+
5459 /**
5560 * Constructor
5661 *
@@ -76,6 +81,7 @@ public function __construct(DeploymentConfig\Reader $reader, $overrideData = [])
7681 */
7782 public function get ($ key = null , $ defaultValue = null )
7883 {
84+ //if no key is requested, then all config is returned.
7985 if ($ key === null ) {
8086 if (empty ($ this ->flatData )) {
8187 $ this ->reloadData ();
@@ -84,7 +90,7 @@ public function get($key = null, $defaultValue = null)
8490 }
8591 $ result = $ this ->getByKey ($ key );
8692 if ($ result === null ) {
87- if (empty ($ this ->flatData )) {
93+ if (empty ($ this ->flatData ) || count ( $ this -> getAllEnvOverrides ()) ) {
8894 $ this ->reloadData ();
8995 }
9096 $ result = $ this ->getByKey ($ key );
@@ -181,19 +187,29 @@ private function reloadData(): void
181187 );
182188 // flatten data for config retrieval using get()
183189 $ this ->flatData = $ this ->flattenParams ($ this ->data );
190+ $ this ->flatData = $ this ->getAllEnvOverrides () + $ this ->flatData ;
191+ }
184192
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+ }
195210 }
196211 }
212+ return $ this ->envOverrides ;
197213 }
198214
199215 /**
0 commit comments