Skip to content

Commit 95cb790

Browse files
author
Ivan Gavryshko
committed
MAGETWO-35009: Add update command and delete old segment classes
- modified DeploymentConfig::flattenParams so we will be able to access to any key in config
1 parent 487b35d commit 95cb790

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

lib/internal/Magento/Framework/App/DeploymentConfig.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,31 @@ private function load()
141141
* Convert associative array of arbitrary depth to a flat associative array with concatenated key path as keys
142142
*
143143
* @param array $params
144+
* @param string $path
144145
* @return array
145146
* @throws \Exception
146147
*/
147-
private function flattenParams(array $params)
148+
private function flattenParams(array $params, $path = null)
148149
{
149-
$result = [];
150-
foreach ($params as $key => $value) {
151-
if (is_array($value)) {
152-
$subParams = $this->flattenParams($value);
153-
foreach ($subParams as $subKey => $subValue) {
154-
if (isset($result[$key . '/' . $subKey])) {
155-
throw new \Exception("Key collision {$subKey} is already defined.");
156-
}
157-
$result[$key . '/' . $subKey] = $subValue;
150+
$cache = [];
151+
152+
if (is_array($params)) {
153+
foreach ($params as $key => $param) {
154+
if ($path) {
155+
$newPath = $path . '/' . $key;
156+
} else {
157+
$newPath = $key;
158158
}
159-
} else {
160-
if (isset($result[$key])) {
161-
throw new \Exception("Key collision {$subKey} is already defined.");
159+
if (isset($cache[$newPath])) {
160+
throw new \Exception("Key collision {$newPath} is already defined.");
161+
}
162+
$cache[$newPath] = $param;
163+
if (is_array($param)) {
164+
$cache = array_merge($cache, $this->flattenParams($param, $newPath));
162165
}
163-
$result[$key] = $value;
164166
}
165167
}
166-
return $result;
168+
169+
return $cache;
167170
}
168171
}

lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ class DeploymentConfigTest extends \PHPUnit_Framework_TestCase
2626
*/
2727
private static $flattenedFixture = [
2828
'configData1' => 'scalar_value',
29+
'configData2' => [
30+
'foo' => 1,
31+
'bar' => ['baz' => 2],
32+
],
2933
'configData2/foo' => 1,
34+
'configData2/bar' => ['baz' => 2],
3035
'configData2/bar/baz' => 2,
3136
];
3237

0 commit comments

Comments
 (0)