From f0db808fd13479e635eec8dd2926a6e920a1d7dd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2011 11:18:07 -0500 Subject: [PATCH] refactor the validator class. --- system/validator.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/system/validator.php b/system/validator.php index 6be8771a..3a574f98 100644 --- a/system/validator.php +++ b/system/validator.php @@ -38,12 +38,19 @@ class Validator { public $language; /** - * The "size" related validation rules. + * The size related validation rules. * * @var array */ protected $size_rules = array('size', 'between', 'min', 'max'); + /** + * The numeric related validation rules. + * + * @var array + */ + protected $numeric_rules = array('numeric', 'integer'); + /** * Create a new validator instance. * @@ -250,7 +257,7 @@ protected function validate_max($attribute, $parameters) */ protected function get_size($attribute) { - if (is_numeric($this->attributes[$attribute]) and $this->has_rule($attribute, array('integer', 'numeric'))) + if (is_numeric($this->attributes[$attribute]) and $this->has_rule($attribute, $this->numeric_rules)) { return $this->attributes[$attribute]; } @@ -423,7 +430,7 @@ protected function get_message($attribute, $rule) // For "size" rules that are validating strings or files, we need to adjust // the default error message for the appropriate type. - if (in_array($rule, $this->size_rules) and ! $this->has_rule($attribute, array('numeric', 'integer'))) + if (in_array($rule, $this->size_rules) and ! $this->has_rule($attribute, $this->numeric_rules)) { return (array_key_exists($attribute, $_FILES)) ? rtrim($message, '.').' '.Lang::line('validation.kilobytes')->get($this->language).'.'