37 lines
786 B
PHP
37 lines
786 B
PHP
<?php
|
|
|
|
namespace App\Domains\Tenant\Support;
|
|
|
|
class TenantDomainNormalizer
|
|
{
|
|
public static function hasValue(mixed $domain): bool
|
|
{
|
|
return is_string($domain) && trim(urldecode($domain)) !== '';
|
|
}
|
|
|
|
public static function normalize(mixed $domain): ?string
|
|
{
|
|
if (! is_string($domain)) {
|
|
return null;
|
|
}
|
|
|
|
$decodedDomain = trim(urldecode($domain));
|
|
|
|
if ($decodedDomain === '') {
|
|
return null;
|
|
}
|
|
|
|
$candidate = str_contains($decodedDomain, '://')
|
|
? $decodedDomain
|
|
: "//{$decodedDomain}";
|
|
|
|
$host = parse_url($candidate, PHP_URL_HOST);
|
|
|
|
if (! is_string($host) || $host === '') {
|
|
return null;
|
|
}
|
|
|
|
return strtolower($host);
|
|
}
|
|
}
|