diff --git a/framework/validators/BooleanValidator.php b/framework/validators/BooleanValidator.php index 427fa44..7a7b68f 100644 --- a/framework/validators/BooleanValidator.php +++ b/framework/validators/BooleanValidator.php @@ -60,6 +60,15 @@ class BooleanValidator extends Validator } } + public function validateValue($value) + { + if ($this->allowEmpty && $this->isEmpty($value)) { + return; + } + return ($this->strict || $value == $this->trueValue || $value == $this->falseValue) + && (!$this->strict || $value === $this->trueValue || $value === $this->falseValue); + } + /** * Returns the JavaScript needed for performing client-side validation. * @param \yii\base\Model $object the data object being validated diff --git a/framework/validators/Validator.php b/framework/validators/Validator.php index b688f32..00a88ba 100644 --- a/framework/validators/Validator.php +++ b/framework/validators/Validator.php @@ -8,6 +8,7 @@ namespace yii\validators; use yii\base\Component; +use yii\base\NotSupportedException; /** * Validator is the base class for all validators. @@ -81,7 +82,7 @@ abstract class Validator extends Component */ public $message; /** - * @var array list of scenarios that the validator should be applied. + * @var array list of scenarios that the validator can be applied to. */ public $on = array(); /** @@ -174,6 +175,11 @@ abstract class Validator extends Component } } + public function validateValue($value) + { + throw new NotSupportedException(__CLASS__ . ' does not support validateValue().'); + } + /** * Returns the JavaScript needed for performing client-side validation. *