Skip to content

Commit 22af11e

Browse files
committed
Merge branch 'MAGETWO-83646' into Chaika_2.1.13_PR4
2 parents 918dd05 + 968f200 commit 22af11e

File tree

3 files changed

+48
-17
lines changed

3 files changed

+48
-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;
@@ -84,12 +85,12 @@ private function loadConfig()
8485
}
8586
}
8687

87-
foreach ($config as $scope => &$item) {
88+
foreach ($config as $scope => $item) {
8889
if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
89-
$item = $this->converter->convert($item);
90+
$config[$scope] = $this->converter->convert($item);
9091
} else {
91-
foreach ($item as &$scopeItems) {
92-
$scopeItems = $this->converter->convert($scopeItems);
92+
foreach ($item as $scopeCode => $scopeItems) {
93+
$config[$scope][$scopeCode] = $this->converter->convert($scopeItems);
9394
}
9495
}
9596
}

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

Lines changed: 19 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,36 @@ 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+
40+
if (count($parts) > 0) {
41+
$parts = array_reverse($parts);
42+
43+
$result = $value;
44+
foreach ($parts as $part) {
45+
$part = trim($part);
46+
if ($part !== '') {
47+
$result = [$part => $result];
48+
}
4249
}
43-
$currentPointer = & $currentPointer[$segment];
50+
51+
$container = array_merge_recursive($container, $result);
4452
}
45-
$currentPointer = $value;
53+
return $container;
4654
}
4755
}

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)