const TYPE_INTEGER = 1;
const TYPE_STRING = 2;
+ const TYPE_BOOL = 3;
/**
* Initialize a new DatabaseObject-related action.
* @param string $variableName
* @param boolean $allowEmpty
* @param string $arrayIndex
+ * @return integer
*/
protected function readInteger($variableName, $allowEmpty = false, $arrayIndex = '') {
- $this->readValue($variableName, $allowEmpty, $arrayIndex, self::TYPE_INTEGER);
+ return $this->readValue($variableName, $allowEmpty, $arrayIndex, self::TYPE_INTEGER);
}
/**
* @param string $variableName
* @param boolean $allowEmpty
* @param string $arrayIndex
+ * @return string
*/
protected function readString($variableName, $allowEmpty = false, $arrayIndex = '') {
- $this->readValue($variableName, $allowEmpty, $arrayIndex, self::TYPE_STRING);
+ return $this->readValue($variableName, $allowEmpty, $arrayIndex, self::TYPE_STRING);
+ }
+
+ /**
+ * Reads a boolean value and validates it.
+ *
+ * @param string $variableName
+ * @param boolean $allowEmpty
+ * @param string $arrayIndex
+ * @return boolean
+ */
+ protected function readBool($variableName, $allowEmpty = false, $arrayIndex = '') {
+ return $this->readValue($variableName, $allowEmpty, $arrayIndex, self::TYPE_BOOL);
}
/**
}
}
break;
+
+ case self::TYPE_BOOL:
+ if (!isset($target[$variableName])) {
+ if ($allowEmpty) {
+ $target[$variableName] = false;
+ }
+ else {
+ throw new UserInputException($variableName);
+ }
+ }
+ else {
+ $target[$variableName] = (bool) $target[$variableName];
+ }
+ break;
}
+ return $target[$variableName];
}
/**