From 62fd92bf72334277e59ac0b07806c0d4dc4774be Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 3 Apr 2013 14:51:15 -0400 Subject: [PATCH] validator wip --- framework/validators/BooleanValidator.php | 9 +++++++++ framework/validators/Validator.php | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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. *