[TASK] Differentiate between associative and nonaccociative arrays when mapping to object

This commit is contained in:
Philipp Dieter 2021-11-22 15:20:35 +01:00
parent 8dbc5791d2
commit 700e592f05
2 changed files with 16 additions and 4 deletions

View File

@ -141,9 +141,6 @@ trait ValidationTrait
if (!$validationResult->isValid()) {
$this->isValid = false;
$this->responseStatus = [400 => 'validationError'];
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
// $validationResult->getErrors(), false, 9, true
//);
foreach ($validationResult->getErrors() as $error){
$field = implode('.', $error->dataPointer());
if ($error->keyword() == 'required') {

View File

@ -22,7 +22,11 @@ class ArrayUtility
*/
public static function toObject($array) {
if (is_array($array)) {
return (object) array_map([__CLASS__, __METHOD__], $array);
if (self::isAssoc($array)) {
return (object) array_map([__CLASS__, __METHOD__], $array);
} else {
return array_map([__CLASS__, __METHOD__], $array);
}
} else {
return $array;
}
@ -46,4 +50,15 @@ class ArrayUtility
return $array;
}
/**
*
*/
public static function isAssoc(array $arr) {
if (array() === $arr) {
return false;
}
return array_keys($arr) !== range(0, count($arr) - 1);
}
}