Skip to content

Commit b0babda

Browse files
author
Alexander Akimov
authored
Merge pull request #1867 from magento-chaika/Chaika_PR_2.2.4
Chaika_PR_2.2.4
2 parents 3c59bd5 + 6979f69 commit b0babda

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Config\App\Config\Source;
78

89
use Magento\Framework\App\Config\ConfigSourceInterface;
@@ -88,12 +89,12 @@ private function loadConfig()
8889
}
8990
}
9091

91-
foreach ($config as $scope => &$item) {
92+
foreach ($config as $scope => $item) {
9293
if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
93-
$item = $this->converter->convert($item);
94+
$config[$scope] = $this->converter->convert($item);
9495
} else {
95-
foreach ($item as &$scopeItems) {
96-
$scopeItems = $this->converter->convert($scopeItems);
96+
foreach ($item as $scopeCode => $scopeItems) {
97+
$config[$scope][$scopeCode] = $this->converter->convert($scopeItems);
9798
}
9899
}
99100
}

lib/internal/Magento/Framework/App/Config/Scope/Converter.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright © Magento, Inc. All rights reserved.
66
* See COPYING.txt for license details.
77
*/
8+
89
namespace Magento\Framework\App\Config\Scope;
910

1011
class Converter implements \Magento\Framework\Config\ConverterInterface
@@ -19,29 +20,33 @@ public function convert($source)
1920
{
2021
$output = [];
2122
foreach ($source as $key => $value) {
22-
$this->_setArrayValue($output, $key, $value);
23+
$output = $this->_setArrayValue($output, $key, $value);
2324
}
2425
return $output;
2526
}
2627

2728
/**
2829
* Set array value by path
2930
*
30-
* @param array &$container
31+
* @param array $container
3132
* @param string $path
3233
* @param string $value
33-
* @return void
34+
* @return array
3435
*/
35-
protected function _setArrayValue(array &$container, $path, $value)
36+
protected function _setArrayValue(array $container, $path, $value)
3637
{
37-
$segments = explode('/', $path);
38-
$currentPointer = & $container;
39-
foreach ($segments as $segment) {
40-
if (!isset($currentPointer[$segment])) {
41-
$currentPointer[$segment] = [];
38+
$parts = explode('/', $path);
39+
if (count($parts) > 0) {
40+
$parts = array_reverse($parts);
41+
$result = $value;
42+
foreach ($parts as $part) {
43+
$part = trim($part);
44+
if ($part !== '') {
45+
$result = [$part => $result];
46+
}
4247
}
43-
$currentPointer = & $currentPointer[$segment];
48+
$container = array_merge_recursive($container, $result);
4449
}
45-
$currentPointer = $value;
50+
return $container;
4651
}
4752
}

lib/internal/Magento/Framework/App/Test/Unit/Config/Scope/ConverterTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Framework\App\Test\Unit\Config\Scope;
78

89
class ConverterTest extends \PHPUnit\Framework\TestCase
@@ -19,8 +20,29 @@ protected function setUp()
1920

2021
public function testConvert()
2122
{
22-
$data = ['some/config/path1' => 'value1', 'some/config/path2' => 'value2'];
23-
$expectedResult = ['some' => ['config' => ['path1' => 'value1', 'path2' => 'value2']]];
23+
$data = [
24+
'some/config/path1' => 'value1',
25+
'some/config/path2' => 'value2',
26+
'some/config/path2' => 'value3',
27+
'some2/config/path2' => 'value4',
28+
'some/bad/path////' => 'value5',
29+
];
30+
$expectedResult = [
31+
'some' => [
32+
'config' => [
33+
'path1' => 'value1',
34+
'path2' => 'value3',
35+
],
36+
'bad' => [
37+
'path' => 'value5',
38+
],
39+
],
40+
'some2' => [
41+
'config' => [
42+
'path2' => 'value4',
43+
]
44+
]
45+
];
2446
$this->assertEquals($expectedResult, $this->_model->convert($data));
2547
}
2648
}

0 commit comments

Comments
 (0)