@@ -25,7 +25,7 @@ class ArrayLoader implements LoaderInterface
25
25
*/
26
26
public function load ($ resource , $ locale , $ domain = 'messages ' )
27
27
{
28
- $ this ->flatten ($ resource );
28
+ $ resource = $ this ->flatten ($ resource );
29
29
$ catalogue = new MessageCatalogue ($ locale );
30
30
$ catalogue ->add ($ resource , $ domain );
31
31
@@ -40,27 +40,20 @@ public function load($resource, $locale, $domain = 'messages')
40
40
* Becomes:
41
41
* 'key.key2.key3' => 'value'
42
42
*
43
- * This function takes an array by reference and will modify it
44
- *
45
- * @param array &$messages The array that will be flattened
46
- * @param array $subnode Current subnode being parsed, used internally for recursive calls
47
- * @param string $path Current path being parsed, used internally for recursive calls
48
43
*/
49
- private function flatten (array & $ messages, array $ subnode = null , $ path = null )
44
+ private function flatten (array $ messages): array
50
45
{
51
- if (null === $ subnode ) {
52
- $ subnode = &$ messages ;
53
- }
54
- foreach ($ subnode as $ key => $ value ) {
46
+ $ result = [];
47
+ foreach ($ messages as $ key => $ value ) {
55
48
if (\is_array ($ value )) {
56
- $ nodePath = $ path ? $ path .'. ' .$ key : $ key ;
57
- $ this ->flatten ($ messages , $ value , $ nodePath );
58
- if (null === $ path ) {
59
- unset($ messages [$ key ]);
49
+ foreach ($ this ->flatten ($ value ) as $ k => $ v ) {
50
+ $ result [$ key .'. ' .$ k ] = $ v ;
60
51
}
61
- } elseif ( null !== $ path ) {
62
- $ messages [ $ path . ' . ' . $ key ] = $ value ;
52
+ } else {
53
+ $ result [ $ key ] = $ value ;
63
54
}
64
55
}
56
+
57
+ return $ result ;
65
58
}
66
59
}
0 commit comments