/
Converter.php
47 lines (45 loc) · 1.17 KB
/
Converter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Configuration data converter. Converts associative array to tree array
*
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\App\Config\Scope;
class Converter implements \Magento\Framework\Config\ConverterInterface
{
/**
* Convert config data
*
* @param array $source
* @return array
*/
public function convert($source)
{
$output = [];
foreach ($source as $key => $value) {
$this->_setArrayValue($output, $key, $value);
}
return $output;
}
/**
* Set array value by path
*
* @param array &$container
* @param string $path
* @param string $value
* @return void
*/
protected function _setArrayValue(array &$container, $path, $value)
{
$segments = explode('/', $path);
$currentPointer = & $container;
foreach ($segments as $segment) {
if (!isset($currentPointer[$segment])) {
$currentPointer[$segment] = [];
}
$currentPointer = & $currentPointer[$segment];
}
$currentPointer = $value;
}
}