File tree Expand file tree Collapse file tree 2 files changed +23
-15
lines changed
lib/internal/Magento/Framework/App Expand file tree Collapse file tree 2 files changed +23
-15
lines changed Original file line number Diff line number Diff line change @@ -141,28 +141,31 @@ private function load()
141
141
* Convert associative array of arbitrary depth to a flat associative array with concatenated key path as keys
142
142
*
143
143
* @param array $params
144
+ * @param string $path
144
145
* @return array
145
146
* @throws \Exception
146
147
*/
147
- private function flattenParams (array $ params )
148
+ private function flattenParams (array $ params, $ path = null )
148
149
{
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 ;
158
158
}
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 ));
162
165
}
163
- $ result [$ key ] = $ value ;
164
166
}
165
167
}
166
- return $ result ;
168
+
169
+ return $ cache ;
167
170
}
168
171
}
Original file line number Diff line number Diff line change @@ -26,7 +26,12 @@ class DeploymentConfigTest extends \PHPUnit_Framework_TestCase
26
26
*/
27
27
private static $ flattenedFixture = [
28
28
'configData1 ' => 'scalar_value ' ,
29
+ 'configData2 ' => [
30
+ 'foo ' => 1 ,
31
+ 'bar ' => ['baz ' => 2 ],
32
+ ],
29
33
'configData2/foo ' => 1 ,
34
+ 'configData2/bar ' => ['baz ' => 2 ],
30
35
'configData2/bar/baz ' => 2 ,
31
36
];
32
37
You can’t perform that action at this time.
0 commit comments