Last active
October 21, 2022 11:59
-
-
Save cmuench/de27258f0b4ccb8df3dee2e8507e935d to your computer and use it in GitHub Desktop.
Magento PR-33803 - compatible for Magento 2.4.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/vendor/magento/framework/App/DeploymentConfig.php 2022-03-08 00:52:02.000000000 +0100 | |
+++ b/vendor/magento/framework/App/DeploymentConfig.php 2022-06-29 14:51:07.639221346 +0200 | |
@@ -35,14 +35,14 @@ | |
* | |
* @var array | |
*/ | |
- private $data; | |
+ private $data = []; | |
/** | |
* Flattened data | |
* | |
* @var array | |
*/ | |
- private $flatData; | |
+ private $flatData = []; | |
/** | |
* Injected configuration data | |
@@ -76,16 +76,18 @@ | |
*/ | |
public function get($key = null, $defaultValue = null) | |
{ | |
- $this->load(); | |
if ($key === null) { | |
+ if (empty($this->flatData)) { | |
+ $this->reloadData(); | |
+ } | |
return $this->flatData; | |
} | |
- | |
- if (array_key_exists($key, $this->flatData) && $this->flatData[$key] === null) { | |
- return ''; | |
+ $result = $this->getByKey($key); | |
+ if ($result === null) { | |
+ $this->reloadData(); | |
+ $result = $this->getByKey($key); | |
} | |
- | |
- return $this->flatData[$key] ?? $defaultValue; | |
+ return $result ?? $defaultValue; | |
} | |
/** | |
@@ -97,27 +99,31 @@ | |
*/ | |
public function isAvailable() | |
{ | |
- $this->load(); | |
- return isset($this->flatData[ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE]); | |
+ return $this->get(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE) !== null; | |
} | |
/** | |
* Gets a value specified key from config data | |
* | |
- * @param string $key | |
+ * @param string|null $key | |
* @return null|mixed | |
* @throws FileSystemException | |
* @throws RuntimeException | |
*/ | |
public function getConfigData($key = null) | |
{ | |
- $this->load(); | |
- | |
- if ($key !== null && !isset($this->data[$key])) { | |
- return null; | |
+ if ($key === null) { | |
+ if (empty($this->data)) { | |
+ $this->reloadData(); | |
+ } | |
+ return $this->data; | |
} | |
- | |
- return $this->data[$key] ?? $this->data; | |
+ $result = $this->getConfigDataByKey($key); | |
+ if ($result === null) { | |
+ $this->reloadData(); | |
+ $result = $this->getConfigDataByKey($key); | |
+ } | |
+ return $result; | |
} | |
/** | |
@@ -127,7 +133,38 @@ | |
*/ | |
public function resetData() | |
{ | |
- $this->data = null; | |
+ $this->data = []; | |
+ $this->flatData = []; | |
+ } | |
+ | |
+ /** | |
+ * Loads the configuration data | |
+ * | |
+ * @return void | |
+ * @throws FileSystemException | |
+ * @throws RuntimeException | |
+ */ | |
+ private function reloadData(): void | |
+ { | |
+ $this->data = $this->reader->load(); | |
+ if ($this->overrideData) { | |
+ $this->data = array_replace($this->data, $this->overrideData); | |
+ } | |
+ // flatten data for config retrieval using get() | |
+ $this->flatData = $this->flattenParams($this->data); | |
+ | |
+ // allow reading values from env variables by convention | |
+ // MAGENTO_DC_{path}, like db/connection/default/host => | |
+ // can be overwritten by MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST | |
+ foreach (getenv() as $key => $value) { | |
+ if (false !== \strpos($key, self::MAGENTO_ENV_PREFIX) | |
+ && $key !== self::OVERRIDE_KEY | |
+ ) { | |
+ // convert MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST into db/connection/default/host | |
+ $flatKey = strtolower(str_replace([self::MAGENTO_ENV_PREFIX, '__'], ['', '/'], $key)); | |
+ $this->flatData[$flatKey] = $value; | |
+ } | |
+ } | |
} | |
/** | |
@@ -140,8 +177,7 @@ | |
*/ | |
public function isDbAvailable() | |
{ | |
- $this->load(); | |
- return isset($this->data['db']); | |
+ return $this->getConfigData('db') !== null; | |
} | |
/** | |
@@ -158,39 +194,6 @@ | |
} | |
/** | |
- * Loads the configuration data | |
- * | |
- * @return void | |
- * @throws FileSystemException | |
- * @throws RuntimeException | |
- */ | |
- private function load() | |
- { | |
- if (empty($this->data)) { | |
- $this->data = array_replace( | |
- $this->reader->load(), | |
- $this->overrideData ?? [], | |
- $this->getEnvOverride() | |
- ); | |
- // flatten data for config retrieval using get() | |
- $this->flatData = $this->flattenParams($this->data); | |
- | |
- // allow reading values from env variables by convention | |
- // MAGENTO_DC_{path}, like db/connection/default/host => | |
- // can be overwritten by MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST | |
- foreach (getenv() as $key => $value) { | |
- if (false !== \strpos($key, self::MAGENTO_ENV_PREFIX) | |
- && $key !== self::OVERRIDE_KEY | |
- ) { | |
- // convert MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST into db/connection/default/host | |
- $flatKey = strtolower(str_replace([self::MAGENTO_ENV_PREFIX, '__'], ['', '/'], $key)); | |
- $this->flatData[$flatKey] = $value; | |
- } | |
- } | |
- } | |
- } | |
- | |
- /** | |
* Array keys conversion | |
* | |
* Convert associative array of arbitrary depth to a flat associative array with concatenated key path as keys | |
@@ -236,4 +239,26 @@ | |
return $flattenResult; | |
} | |
+ | |
+ /** | |
+ * @param string|null $key | |
+ * @return mixed|null | |
+ */ | |
+ private function getByKey(?string $key) | |
+ { | |
+ if (array_key_exists($key, $this->flatData) && $this->flatData[$key] === null) { | |
+ return ''; | |
+ } | |
+ | |
+ return $this->flatData[$key] ?? null; | |
+ } | |
+ | |
+ /** | |
+ * @param string|null $key | |
+ * @return mixed|null | |
+ */ | |
+ private function getConfigDataByKey(?string $key) | |
+ { | |
+ return $this->data[$key] ?? null; | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment