Commaaa2
This commit is contained in:
@@ -36,7 +36,7 @@ class ArrayConverter
|
||||
$tree = [];
|
||||
|
||||
foreach ($messages as $id => $value) {
|
||||
$referenceToElement = &self::getElementByPath($tree, explode('.', $id));
|
||||
$referenceToElement = &self::getElementByPath($tree, self::getKeyParts($id));
|
||||
|
||||
$referenceToElement = $value;
|
||||
|
||||
@@ -46,7 +46,7 @@ class ArrayConverter
|
||||
return $tree;
|
||||
}
|
||||
|
||||
private static function &getElementByPath(array &$tree, array $parts)
|
||||
private static function &getElementByPath(array &$tree, array $parts): mixed
|
||||
{
|
||||
$elem = &$tree;
|
||||
$parentOfElem = null;
|
||||
@@ -63,6 +63,7 @@ class ArrayConverter
|
||||
$elem = &$elem[implode('.', \array_slice($parts, $i))];
|
||||
break;
|
||||
}
|
||||
|
||||
$parentOfElem = &$elem;
|
||||
$elem = &$elem[$part];
|
||||
}
|
||||
@@ -82,7 +83,7 @@ class ArrayConverter
|
||||
return $elem;
|
||||
}
|
||||
|
||||
private static function cancelExpand(array &$tree, string $prefix, array $node)
|
||||
private static function cancelExpand(array &$tree, string $prefix, array $node): void
|
||||
{
|
||||
$prefix .= '.';
|
||||
|
||||
@@ -94,4 +95,48 @@ class ArrayConverter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private static function getKeyParts(string $key): array
|
||||
{
|
||||
$parts = explode('.', $key);
|
||||
$partsCount = \count($parts);
|
||||
|
||||
$result = [];
|
||||
$buffer = '';
|
||||
|
||||
foreach ($parts as $index => $part) {
|
||||
if (0 === $index && '' === $part) {
|
||||
$buffer = '.';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($index === $partsCount - 1 && '' === $part) {
|
||||
$buffer .= '.';
|
||||
$result[] = $buffer;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($parts[$index + 1]) && '' === $parts[$index + 1]) {
|
||||
$buffer .= $part;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($buffer) {
|
||||
$result[] = $buffer.$part;
|
||||
$buffer = '';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = $part;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user