28 lines
776 B
PHP
28 lines
776 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Domain\Models\ValueObjects\Matricule as ValueObjectsMatricule;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class Matricule implements ValidationRule
|
|
{
|
|
/** @param \Closure(string, ?string=):\Illuminate\Translation\PotentiallyTranslatedString $fail */
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
try {
|
|
if (! is_numeric($value)) {
|
|
$fail(trans('validation.integer', compact('attribute')));
|
|
|
|
return;
|
|
}
|
|
|
|
new ValueObjectsMatricule(strval($value));
|
|
} catch (\DomainException) {
|
|
$fail(trans('validation.matricule', compact('attribute')));
|
|
}
|
|
}
|
|
}
|