Skip to content

Commit 7941545

Browse files
authored
Merge branch '2.4-develop' into Arrows_regression_issues_2_4_develop_13jan22
2 parents 3821b55 + 519809e commit 7941545

File tree

4 files changed

+40
-55
lines changed

4 files changed

+40
-55
lines changed

app/code/Magento/Config/App/Config/Source/EnvironmentConfigSource.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ class EnvironmentConfigSource implements ConfigSourceInterface
3333
*/
3434
private $placeholder;
3535

36+
/**
37+
* cache for loadConfig()
38+
*
39+
* @var array|null
40+
*/
41+
private $loadConfigCache;
42+
43+
/**
44+
* cache for loadConfig()
45+
*
46+
* @var string|null
47+
*/
48+
private $loadConfigCacheEnv;
49+
3650
/**
3751
* @param ArrayManager $arrayManager
3852
* @param PlaceholderFactory $placeholderFactory
@@ -57,27 +71,32 @@ public function get($path = '')
5771

5872
/**
5973
* Loads config from environment variables.
74+
* Caching the result for when this method is called multiple times.
75+
* The environment variables don't change in run time, so it is safe to cache.
6076
*
6177
* @return array
6278
*/
6379
private function loadConfig()
6480
{
6581
$config = [];
66-
82+
// phpcs:disable Magento2.Security.Superglobal
6783
$environmentVariables = $_ENV;
68-
84+
// phpcs:enable
85+
if (null !== $this->loadConfigCache && $this->loadConfigCacheEnv === $environmentVariables) {
86+
return $this->loadConfigCache;
87+
}
6988
foreach ($environmentVariables as $template => $value) {
7089
if (!$this->placeholder->isApplicable($template)) {
7190
continue;
7291
}
73-
7492
$config = $this->arrayManager->set(
7593
$this->placeholder->restore($template),
7694
$config,
7795
$value
7896
);
7997
}
80-
98+
$this->loadConfigCache = $config;
99+
$this->loadConfigCacheEnv = $environmentVariables;
81100
return $config;
82101
}
83102
}

app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,11 @@ private function filterPaths(string $prefix, array $groups, array $systemXmlConf
323323
public function filterNodes(array $configData): array
324324
{
325325
if (!empty($configData['groups'])) {
326-
$systemXmlPathsFromKeys = array_keys($this->_configStructure->getFieldPaths());
327-
$systemXmlPathsFromValues = array_reduce(
328-
array_values($this->_configStructure->getFieldPaths()),
329-
'array_merge',
330-
[]
331-
);
332326
//Full list of paths defined in system.xml
333-
$systemXmlConfig = array_merge($systemXmlPathsFromKeys, $systemXmlPathsFromValues);
334-
327+
$fieldPaths = $this->_configStructure->getFieldPaths();
328+
$systemXmlConfig = array_merge(array_keys($fieldPaths), ...array_values($fieldPaths));
335329
$configData['groups'] = $this->filterPaths($configData['section'], $configData['groups'], $systemXmlConfig);
336330
}
337-
338331
return $configData;
339332
}
340333

app/code/Magento/Config/Model/Config/Structure.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,32 +384,22 @@ public function getFieldPaths()
384384
* Iteration that collects config field paths recursively from config files.
385385
*
386386
* @param array $elements The elements to be parsed
387+
* @param array $result used for recursive calls
387388
* @return array An array of config path to config structure path map
388389
*/
389-
private function getFieldsRecursively(array $elements = [])
390+
private function getFieldsRecursively(array $elements = [], &$result = [])
390391
{
391-
$result = [];
392-
393392
foreach ($elements as $element) {
394393
if (isset($element['children'])) {
395-
$result = array_merge_recursive(
396-
$result,
397-
$this->getFieldsRecursively($element['children'])
398-
);
394+
$this->getFieldsRecursively($element['children'], $result);
399395
} else {
400396
if ($element['_elementType'] === 'field') {
401397
$structurePath = (isset($element['path']) ? $element['path'] . '/' : '') . $element['id'];
402398
$configPath = isset($element['config_path']) ? $element['config_path'] : $structurePath;
403-
404-
if (!isset($result[$configPath])) {
405-
$result[$configPath] = [];
406-
}
407-
408399
$result[$configPath][] = $structurePath;
409400
}
410401
}
411402
}
412-
413403
return $result;
414404
}
415405
}

app/code/Magento/Store/Model/Config/Placeholder.php

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,30 @@ public function __construct(\Magento\Framework\App\RequestInterface $request, $u
4343
*
4444
* @param array $data
4545
* @return array
46+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4647
*/
4748
public function process(array $data = [])
4849
{
49-
// check provided arguments
5050
if (empty($data)) {
5151
return [];
5252
}
53-
54-
// initialize $pointer, $parents and $level variable
55-
reset($data);
56-
$pointer = &$data;
57-
$parents = [];
58-
$level = 0;
59-
60-
while ($level >= 0) {
61-
$current = &$pointer[key($pointer)];
62-
if (is_array($current)) {
63-
reset($current);
64-
$parents[$level] = &$pointer;
65-
$pointer = &$current;
66-
$level++;
67-
} else {
68-
$current = $this->_processPlaceholders($current, $data);
69-
70-
// move pointer of last queue layer to next element
71-
// or remove layer if all path elements were processed
72-
while ($level >= 0 && next($pointer) === false) {
73-
$level--;
74-
// removal of last element of $parents is skipped here for better performance
75-
// on next iteration that element will be overridden
76-
$pointer = &$parents[$level];
53+
array_walk_recursive(
54+
$data,
55+
function (&$value, $key, $data) {
56+
if (is_string($value) && str_contains($value, '{')) { // If _getPlaceholder() would do nothing, skip
57+
$value = $this->_processPlaceholders($value, $data);
7758
}
78-
}
79-
}
80-
59+
},
60+
$data
61+
);
8162
return $data;
8263
}
8364

8465
/**
8566
* Process array data recursively
8667
*
8768
* @deprecated 101.0.4 This method isn't used in process() implementation anymore
69+
* @see process()
8870
*
8971
* @param array &$data
9072
* @param string $path
@@ -179,6 +161,7 @@ protected function _getValue($path, array $data)
179161
* Set array value by path
180162
*
181163
* @deprecated 101.0.4 This method isn't used in process() implementation anymore
164+
* @see process()
182165
*
183166
* @param array &$container
184167
* @param string $path
@@ -187,7 +170,7 @@ protected function _getValue($path, array $data)
187170
*/
188171
protected function _setValue(array &$container, $path, $value)
189172
{
190-
$segments = explode('/', (string)$path);
173+
$segments = explode('/', (string)$path);
191174
$currentPointer = &$container;
192175
foreach ($segments as $segment) {
193176
if (!isset($currentPointer[$segment])) {

0 commit comments

Comments
 (0)