Added `readStringArray()`
authorAlexander Ebert <ebert@woltlab.com>
Wed, 24 Jun 2015 17:22:38 +0000 (19:22 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 24 Jun 2015 17:22:38 +0000 (19:22 +0200)
wcfsetup/install/files/lib/data/AbstractDatabaseObjectAction.class.php

index 7ba3107252853dfc61a79640f4f5e0fbb289087e..26c5ac1f2967246a8d42e586e082322369b69bdc 100644 (file)
@@ -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;