123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php namespace System\Validation\Rules;
- use System\Validation\Rangable_Rule;
- class Numericality_Of extends Rangable_Rule {
-
- public $only_integer = false;
-
- public $not_valid;
-
- public $not_integer;
-
- public function check($attribute, $attributes)
- {
- if ( ! is_null($nullable = parent::check($attribute, $attributes)))
- {
- return $nullable;
- }
-
-
-
- if ( ! is_numeric($attributes[$attribute]))
- {
- $this->error = 'number_not_valid';
- }
-
-
-
- elseif ($this->only_integer and filter_var($attributes[$attribute], FILTER_VALIDATE_INT) === false)
- {
- $this->error = 'number_not_integer';
- }
-
-
-
- elseif ( ! is_null($this->size) and $attributes[$attribute] != $this->size)
- {
- $this->error = 'number_wrong_size';
- }
-
-
-
- elseif ( ! is_null($this->maximum) and $attributes[$attribute] > $this->maximum)
- {
- $this->error = 'number_too_big';
- }
-
-
-
- elseif ( ! is_null($this->minimum) and $attributes[$attribute] < $this->minimum)
- {
- $this->error = 'number_too_small';
- }
- return is_null($this->error);
- }
-
- public function only_integer()
- {
- $this->only_integer = true;
- return $this;
- }
-
- public function not_valid($message)
- {
- $this->not_valid = $message;
- return $this;
- }
-
- public function not_integer($message)
- {
- $this->not_integer = $message;
- return $this;
- }
- }
|