From 700e592f0566bdc7795d426834177e4d3df07482 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 22 Nov 2021 15:20:35 +0100 Subject: [PATCH] [TASK] Differentiate between associative and nonaccociative arrays when mapping to object --- Classes/Traits/ValidationTrait.php | 3 --- Classes/Utility/ArrayUtility.php | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Classes/Traits/ValidationTrait.php b/Classes/Traits/ValidationTrait.php index b53f47b..945fd9c 100644 --- a/Classes/Traits/ValidationTrait.php +++ b/Classes/Traits/ValidationTrait.php @@ -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') { diff --git a/Classes/Utility/ArrayUtility.php b/Classes/Utility/ArrayUtility.php index 7f2a7a0..f43c961 100644 --- a/Classes/Utility/ArrayUtility.php +++ b/Classes/Utility/ArrayUtility.php @@ -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); + } + }