Upgrade framework
This commit is contained in:
@@ -27,15 +27,13 @@ class ArrayConverter
|
||||
{
|
||||
/**
|
||||
* Converts linear messages array to tree-like array.
|
||||
* For example this rray('foo.bar' => 'value') will be converted to array('foo' => array('bar' => 'value')).
|
||||
* For example this array('foo.bar' => 'value') will be converted to ['foo' => ['bar' => 'value']].
|
||||
*
|
||||
* @param array $messages Linear messages array
|
||||
*
|
||||
* @return array Tree-like messages array
|
||||
*/
|
||||
public static function expandToTree(array $messages)
|
||||
public static function expandToTree(array $messages): array
|
||||
{
|
||||
$tree = array();
|
||||
$tree = [];
|
||||
|
||||
foreach ($messages as $id => $value) {
|
||||
$referenceToElement = &self::getElementByPath($tree, explode('.', $id));
|
||||
@@ -54,7 +52,7 @@ class ArrayConverter
|
||||
$parentOfElem = null;
|
||||
|
||||
foreach ($parts as $i => $part) {
|
||||
if (isset($elem[$part]) && is_string($elem[$part])) {
|
||||
if (isset($elem[$part]) && \is_string($elem[$part])) {
|
||||
/* Process next case:
|
||||
* 'foo': 'test1',
|
||||
* 'foo.bar': 'test2'
|
||||
@@ -62,14 +60,14 @@ class ArrayConverter
|
||||
* $tree['foo'] was string before we found array {bar: test2}.
|
||||
* Treat new element as string too, e.g. add $tree['foo.bar'] = 'test2';
|
||||
*/
|
||||
$elem = &$elem[implode('.', array_slice($parts, $i))];
|
||||
$elem = &$elem[implode('.', \array_slice($parts, $i))];
|
||||
break;
|
||||
}
|
||||
$parentOfElem = &$elem;
|
||||
$elem = &$elem[$part];
|
||||
}
|
||||
|
||||
if (is_array($elem) && count($elem) > 0 && $parentOfElem) {
|
||||
if ($elem && \is_array($elem) && $parentOfElem) {
|
||||
/* Process next case:
|
||||
* 'foo.bar': 'test1'
|
||||
* 'foo': 'test2'
|
||||
@@ -84,12 +82,12 @@ class ArrayConverter
|
||||
return $elem;
|
||||
}
|
||||
|
||||
private static function cancelExpand(array &$tree, $prefix, array $node)
|
||||
private static function cancelExpand(array &$tree, string $prefix, array $node)
|
||||
{
|
||||
$prefix .= '.';
|
||||
|
||||
foreach ($node as $id => $value) {
|
||||
if (is_string($value)) {
|
||||
if (\is_string($value)) {
|
||||
$tree[$prefix.$id] = $value;
|
||||
} else {
|
||||
self::cancelExpand($tree, $prefix.$id, $value);
|
||||
|
||||
Reference in New Issue
Block a user