Files
animethemes-server/app/Rules/Wiki/Resource/AnimeThemeEntryResourceLinkFormatRule.php
T

30 lines
833 B
PHP

<?php
declare(strict_types=1);
namespace App\Rules\Wiki\Resource;
use App\Enums\Models\Wiki\ResourceSite;
use App\Models\Wiki\Anime\Theme\AnimeThemeEntry;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;
use Illuminate\Translation\PotentiallyTranslatedString;
readonly class AnimeThemeEntryResourceLinkFormatRule implements ValidationRule
{
public function __construct(protected ResourceSite $site) {}
/**
* @param Closure(string): PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$pattern = $this->site->getPattern(AnimeThemeEntry::class);
if ($pattern !== null && Str::match($pattern, $value) !== $value) {
$fail(__('validation.regex'));
}
}
}