Skip to content

Commit

Permalink
make requirement and default optional
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Jun 7, 2012
1 parent 1fd5129 commit 55d76e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Controller/Annotations/QueryParam.php
Expand Up @@ -22,9 +22,9 @@ class QueryParam
/** @var string */
public $name;
/** @var string */
public $requirements;
public $requirements = '';
/** @var string */
public $default;
public $default = '';
/** @var string */
public $description;
}
5 changes: 4 additions & 1 deletion Request/QueryFetcher.php
Expand Up @@ -88,7 +88,10 @@ public function get($name, $strict = false)
$param = $this->request->query->get($name, $default);

// Set default if the requirements do not match
if ($param !== $default && !preg_match('#^'.$config->requirements.'$#xs', $param)) {
if ("" !== $config->requirements
&& $param !== $default
&& !preg_match('#^'.$config->requirements.'$#xs', $param)
) {
if ($strict) {
throw new \RuntimeException("Query parameter value '$param', does not match requirements '{$config->requirements}'");
}
Expand Down

0 comments on commit 55d76e1

Please sign in to comment.