mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-29 01:58:56 +02:00
* chore: address deprecations to validation rules in Laravel 10 * style: fix StyleCI findings
44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Rules\Wiki\Resource;
|
|
|
|
use App\Enums\Models\Wiki\ResourceSite;
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Translation\PotentiallyTranslatedString;
|
|
|
|
/**
|
|
* Class ResourceSiteMatchesLinkRule.
|
|
*/
|
|
readonly class ResourceSiteMatchesLinkRule implements ValidationRule
|
|
{
|
|
/**
|
|
* Create a new rule instance.
|
|
*
|
|
* @param string $link
|
|
* @return void
|
|
*/
|
|
public function __construct(protected string $link)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Run the validation rule.
|
|
*
|
|
* @param string $attribute
|
|
* @param mixed $value
|
|
* @param Closure(string): PotentiallyTranslatedString $fail
|
|
* @return void
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
$domain = ResourceSite::getDomain($value);
|
|
|
|
if (! empty($domain) && $domain !== parse_url($this->link, PHP_URL_HOST)) {
|
|
$fail(__('validation.resource_link_site_mismatch'));
|
|
}
|
|
}
|
|
}
|