mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-21 19:01:37 +00:00
23 lines
563 B
PHP
Executable File
23 lines
563 B
PHP
Executable File
<?php
|
|
|
|
namespace App\ValidationRules;
|
|
|
|
use Cron\CronExpression;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class CronRule implements ValidationRule
|
|
{
|
|
public function __construct(private readonly bool $acceptCustom = false) {}
|
|
|
|
public function validate(string $attribute, mixed $value, \Closure $fail): void
|
|
{
|
|
if (CronExpression::isValidExpression($value)) {
|
|
return;
|
|
}
|
|
if ($this->acceptCustom && $value === 'custom') {
|
|
return;
|
|
}
|
|
$fail('Invalid frequency')->translate();
|
|
}
|
|
}
|