protected function untangleFilesArray(array $convolutedFiles)
{
$untangledFiles = [];
$fieldPaths = [];
foreach ($convolutedFiles as $firstLevelFieldName => $fieldInformation) {
if (!is_array($fieldInformation['error'])) {
$fieldPaths[] = [$firstLevelFieldName];
} else {
$newFieldPaths = $this->calculateFieldPaths($fieldInformation['error'], $firstLevelFieldName);
array_walk($newFieldPaths, function (&$value) {
$value = explode('/', $value);
});
$fieldPaths = array_merge($fieldPaths, $newFieldPaths);
}
}
foreach ($fieldPaths as $fieldPath) {
if (count($fieldPath) === 1) {
$fileInformation = $convolutedFiles[$fieldPath[0]];
} else {
$fileInformation = [];
foreach ($convolutedFiles[$fieldPath[0]] as $key => $subStructure) {
$fileInformation[$key] = Arrays::getValueByPath($subStructure, array_slice($fieldPath, 1));
}
}
if (isset($fileInformation['error']) && $fileInformation['error'] !== \UPLOAD_ERR_NO_FILE) {
$untangledFiles = Arrays::setValueByPath($untangledFiles, $fieldPath, $fileInformation);
}
}
return $untangledFiles;
}