mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-04 11:45:00 +02:00
30 lines
833 B
PHP
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'));
|
|
}
|
|
}
|
|
}
|