| 1 |
<?php |
| 2 |
|
| 3 |
namespace Rakit\Validation\Rules; |
| 4 |
|
| 5 |
use Rakit\Validation\Rule; |
| 6 |
|
| 7 |
class Before extends Rule |
| 8 |
{ |
| 9 |
use Traits\DateUtilsTrait; |
| 10 |
|
| 11 |
/** @var string */ |
| 12 |
protected $message = "The :attribute must be a date before :time."; |
| 13 |
|
| 14 |
/** @var array */ |
| 15 |
protected $fillableParams = ['time']; |
| 16 |
|
| 17 |
/** |
| 18 |
* Check the $value is valid |
| 19 |
* |
| 20 |
* @param mixed $value |
| 21 |
* @return bool |
| 22 |
* @throws \Exception |
| 23 |
*/ |
| 24 |
public function check($value): bool |
| 25 |
{ |
| 26 |
$this->requireParameters($this->fillableParams); |
| 27 |
$time = $this->parameter('time'); |
| 28 |
|
| 29 |
if (!$this->isValidDate($value)) { |
| 30 |
throw $this->throwException($value); |
| 31 |
} |
| 32 |
|
| 33 |
if (!$this->isValidDate($time)) { |
| 34 |
throw $this->throwException($time); |
| 35 |
} |
| 36 |
|
| 37 |
return $this->getTimeStamp($time) > $this->getTimeStamp($value); |
| 38 |
} |
| 39 |
} |
| 40 |
|