Skip to content

Commit

Permalink
If $err is false, then validator functions return a bool
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Apr 13, 2011
1 parent b5b4eb5 commit 04ca1f6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions klein.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ function addValidator($method, $callback) {
_Validator::$_methods[strtolower($method)] = $callback;
}

class ValidatorException extends Exception {}

class _Validator {

public static $_methods = array();
Expand Down Expand Up @@ -580,9 +582,16 @@ public function __call($method, $args) {
default: $result = call_user_func_array($validator, $args); break;
}

$result = (bool)$result ^ $reverse;

//if $err is false just return the result as a bool
if (false === $this->_err) {
return $result
}

//Throw an exception on failed validation
if (false === (bool)$result ^ $reverse) {
throw new Exception($this->_err);
if (false === $result) {
throw new ValidatorException($this->_err);
}
return $this;
}
Expand Down

0 comments on commit 04ca1f6

Please sign in to comment.