Skip to content

Commit

Permalink
Merge pull request #12 from dasgarner/master
Browse files Browse the repository at this point in the history
Sanitizer: add a getParam call to return the raw param if present.
  • Loading branch information
dasgarner authored Jun 28, 2022
2 parents 00dbe80 + e42cc15 commit 348f9ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Xibo/Support/Sanitizer/RespectSanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Xibo/Support/Sanitizer/SanitizerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 348f9ff

Please sign in to comment.