| 1 |
<?php |
| 2 |
|
| 3 |
namespace Rakit\Validation\Rules; |
| 4 |
|
| 5 |
use Rakit\Validation\Rule; |
| 6 |
|
| 7 |
class Between extends Rule |
| 8 |
{ |
| 9 |
use Traits\SizeTrait; |
| 10 |
|
| 11 |
/** @var string */ |
| 12 |
protected $message = "The :attribute must be between :min and :max"; |
| 13 |
|
| 14 |
/** @var array */ |
| 15 |
protected $fillableParams = ['min', 'max']; |
| 16 |
|
| 17 |
/** |
| 18 |
* Check the $value is valid |
| 19 |
* |
| 20 |
* @param mixed $value |
| 21 |
* @return bool |
| 22 |
*/ |
| 23 |
public function check($value): bool |
| 24 |
{ |
| 25 |
$this->requireParameters($this->fillableParams); |
| 26 |
|
| 27 |
$min = $this->getBytesSize($this->parameter('min')); |
| 28 |
$max = $this->getBytesSize($this->parameter('max')); |
| 29 |
|
| 30 |
$valueSize = $this->getValueSize($value); |
| 31 |
|
| 32 |
if (!is_numeric($valueSize)) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
return ($valueSize >= $min && $valueSize <= $max); |
| 37 |
} |
| 38 |
} |
| 39 |
|