| @@ 6-29 (lines=24) @@ | ||
| 3 | ||
| 4 | use MetaHydrator\Exception\ValidationException; |
|
| 5 | ||
| 6 | class GreaterThanValidator extends AbstractValidator |
|
| 7 | { |
|
| 8 | /** @var mixed */ |
|
| 9 | protected $min; |
|
| 10 | ||
| 11 | public function __construct($min, $errorMessage = "") |
|
| 12 | { |
|
| 13 | parent::__construct($errorMessage); |
|
| 14 | $this->min = $min; |
|
| 15 | } |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param mixed $value |
|
| 19 | * @param $contextObject |
|
| 20 | * |
|
| 21 | * @throws ValidationException |
|
| 22 | */ |
|
| 23 | public function validate($value, $contextObject = null) |
|
| 24 | { |
|
| 25 | if ($value !== null && $value < $this->min) { |
|
| 26 | $this->throw(); |
|
| 27 | } |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||
| @@ 6-29 (lines=24) @@ | ||
| 3 | ||
| 4 | use MetaHydrator\Exception\ValidationException; |
|
| 5 | ||
| 6 | class LessThanValidator extends AbstractValidator |
|
| 7 | { |
|
| 8 | /** @var mixed */ |
|
| 9 | protected $max; |
|
| 10 | ||
| 11 | public function __construct($max, $errorMessage = "") |
|
| 12 | { |
|
| 13 | parent::__construct($errorMessage); |
|
| 14 | $this->max = $max; |
|
| 15 | } |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param mixed $value |
|
| 19 | * @param $contextObject |
|
| 20 | * |
|
| 21 | * @throws ValidationException |
|
| 22 | */ |
|
| 23 | public function validate($value, $contextObject = null) |
|
| 24 | { |
|
| 25 | if ($value !== null && $value > $this->max) { |
|
| 26 | $this->throw(); |
|
| 27 | } |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||