From: Alexander Ebert Date: Wed, 24 Jun 2015 17:22:38 +0000 (+0200) Subject: Added `readStringArray()` X-Git-Tag: 3.0.0_Beta_1~2257 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1c83c6477a1c10920a2c6deb09d350d94ca871f3;p=GitHub%2FWoltLab%2FWCF.git Added `readStringArray()` --- diff --git a/wcfsetup/install/files/lib/data/AbstractDatabaseObjectAction.class.php b/wcfsetup/install/files/lib/data/AbstractDatabaseObjectAction.class.php index 7ba3107252..26c5ac1f29 100644 --- a/wcfsetup/install/files/lib/data/AbstractDatabaseObjectAction.class.php +++ b/wcfsetup/install/files/lib/data/AbstractDatabaseObjectAction.class.php @@ -448,6 +448,17 @@ abstract class AbstractDatabaseObjectAction implements IDatabaseObjectAction, ID $this->readValue($variableName, $allowEmpty, $arrayIndex, self::TYPE_STRING, self::STRUCT_FLAT); } + /** + * Reads a string array and validates it. + * + * @param string $variableName + * @param boolean $allowEmpty + * @param string $arrayIndex + */ + protected function readStringArray($variableName, $allowEmpty = false, $arrayIndex = '') { + $this->readValue($variableName, $allowEmpty, $arrayIndex, self::TYPE_STRING, self::STRUCT_ARRAY); + } + /** * Reads a boolean value and validates it. * @@ -528,16 +539,30 @@ abstract class AbstractDatabaseObjectAction implements IDatabaseObjectAction, ID case self::TYPE_STRING: if (!isset($target[$variableName])) { if ($allowEmpty) { - $target[$variableName] = ''; + $target[$variableName] = ($structure === self::STRUCT_FLAT) ? '' : array(); } else { throw new UserInputException($variableName); } } else { - $target[$variableName] = StringUtil::trim($target[$variableName]); - if (!$allowEmpty && empty($target[$variableName])) { - throw new UserInputException($variableName); + if ($structure === self::STRUCT_FLAT) { + $target[$variableName] = StringUtil::trim($target[$variableName]); + if (!$allowEmpty && empty($target[$variableName])) { + throw new UserInputException($variableName); + } + } + else { + $target[$variableName] = ArrayUtil::trim($target[$variableName]); + if (!is_array($target[$variableName])) { + throw new UserInputException($variableName); + } + + for ($i = 0, $length = count($target[$variableName]); $i < $length; $i++) { + if (empty($target[$variableName][$i])) { + throw new UserInputException($variableName); + } + } } } break;