Files
animethemes-server/app/Rules/Wiki/Resource/ResourceSiteMatchesLinkRule.php
T
paranarimasu e973f68537 feat(admin): upload video action (#436)
* feat(admin): upload video action

* style: fix StyleCI findings

* tests: fix video storage tests
2022-08-15 21:58:42 -05:00

49 lines
1001 B
PHP

<?php
declare(strict_types=1);
namespace App\Rules\Wiki\Resource;
use App\Enums\Models\Wiki\ResourceSite;
use Illuminate\Contracts\Validation\Rule;
/**
* Class ResourceSiteMatchesLinkRule.
*/
class ResourceSiteMatchesLinkRule implements Rule
{
/**
* Create a new rule instance.
*
* @param string $link
* @return void
*/
public function __construct(protected readonly string $link)
{
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value): bool
{
$domain = ResourceSite::getDomain($value);
return empty($domain) || $domain === parse_url($this->link, PHP_URL_HOST);
}
/**
* Get the validation error message.
*
* @return string|array
*/
public function message(): string|array
{
return __('validation.resource_link_site_mismatch');
}
}