refactor the validator class.
This commit is contained in:
parent
3d48b323c3
commit
f0db808fd1
|
@ -38,12 +38,19 @@ class Validator {
|
||||||
public $language;
|
public $language;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "size" related validation rules.
|
* The size related validation rules.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $size_rules = array('size', 'between', 'min', 'max');
|
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.
|
* Create a new validator instance.
|
||||||
*
|
*
|
||||||
|
@ -250,7 +257,7 @@ protected function validate_max($attribute, $parameters)
|
||||||
*/
|
*/
|
||||||
protected function get_size($attribute)
|
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];
|
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
|
// For "size" rules that are validating strings or files, we need to adjust
|
||||||
// the default error message for the appropriate type.
|
// 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))
|
return (array_key_exists($attribute, $_FILES))
|
||||||
? rtrim($message, '.').' '.Lang::line('validation.kilobytes')->get($this->language).'.'
|
? rtrim($message, '.').' '.Lang::line('validation.kilobytes')->get($this->language).'.'
|
||||||
|
|
Loading…
Reference in New Issue