Skip to content

Commit

Permalink
Sanitizer: add a getParam call to return the raw param if present.
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Jun 28, 2022
1 parent 68746a1 commit e42cc15
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 e42cc15

Please sign in to comment.