[TASK] Differentiate between associative and nonaccociative arrays when mapping to object
This commit is contained in:
parent
8dbc5791d2
commit
700e592f05
@ -141,9 +141,6 @@ trait ValidationTrait
|
|||||||
if (!$validationResult->isValid()) {
|
if (!$validationResult->isValid()) {
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
$this->responseStatus = [400 => 'validationError'];
|
$this->responseStatus = [400 => 'validationError'];
|
||||||
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
|
|
||||||
// $validationResult->getErrors(), false, 9, true
|
|
||||||
//);
|
|
||||||
foreach ($validationResult->getErrors() as $error){
|
foreach ($validationResult->getErrors() as $error){
|
||||||
$field = implode('.', $error->dataPointer());
|
$field = implode('.', $error->dataPointer());
|
||||||
if ($error->keyword() == 'required') {
|
if ($error->keyword() == 'required') {
|
||||||
|
@ -22,7 +22,11 @@ class ArrayUtility
|
|||||||
*/
|
*/
|
||||||
public static function toObject($array) {
|
public static function toObject($array) {
|
||||||
if (is_array($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 {
|
} else {
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
@ -46,4 +50,15 @@ class ArrayUtility
|
|||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function isAssoc(array $arr) {
|
||||||
|
if (array() === $arr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return array_keys($arr) !== range(0, count($arr) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user