diff --git a/src/Xibo/Support/Sanitizer/RespectSanitizer.php b/src/Xibo/Support/Sanitizer/RespectSanitizer.php index 8ef28a7..5bf2e55 100644 --- a/src/Xibo/Support/Sanitizer/RespectSanitizer.php +++ b/src/Xibo/Support/Sanitizer/RespectSanitizer.php @@ -73,6 +73,7 @@ private function mergeOptions($options, $key) * Return a failure * @param $options * @throws \Xibo\Support\Exception\InvalidArgumentException + * @return void|\Exception */ private function failure($options) { @@ -103,6 +104,23 @@ private function failureNotExists($options) return $this->failure($options); } + /** @inheritDoc */ + public function getParam($key, $options = []) + { + $options = $this->mergeOptions($options, $key); + + if (!$this->collection->has($key)) { + return $this->failureNotExists($options); + } + + $value = $this->collection->get($key); + if ($value === null || ($value === '' && $options['defaultOnEmptyString'])) { + return $this->failureNotExists($options); + } + + return $value; + } + /** * @inheritdoc */ diff --git a/src/Xibo/Support/Sanitizer/SanitizerInterface.php b/src/Xibo/Support/Sanitizer/SanitizerInterface.php index 79d29a8..66c97f1 100644 --- a/src/Xibo/Support/Sanitizer/SanitizerInterface.php +++ b/src/Xibo/Support/Sanitizer/SanitizerInterface.php @@ -25,6 +25,14 @@ public function setCollection($collection); */ public function setDefaultOptions($options); + /** + * Get the raw param from the collection + * @param string $key The name of the key + * @param array $options Options to apply to the operation + * @return mixed + */ + public function getParam($key, $options = []); + /** * @param string $key The name of the key * @param array $options Options to apply to the operation