<?php
 namespace App\Services\Domain; use App\Models\BlockedDomainPattern; use Illuminate\Support\Facades\Cache; class BlockedDomainChecker { public function check(string $domain): ?BlockedDomainPattern { $domain = $this->normalize($domain); if ($domain === '') { return null; } foreach ($this->patterns() as $pattern) { if ($pattern->matches($domain)) { return $pattern; } } return null; } public function isBlocked(string $domain): bool { return $this->check($domain) !== null; } private function patterns() { return Cache::remember( BlockedDomainPattern::CACHE_KEY, BlockedDomainPattern::CACHE_TTL, fn () => BlockedDomainPattern::active()->get(), ); } private function normalize(string $domain): string { $domain = trim(mb_strtolower($domain)); if ($domain === '') { return ''; } if (function_exists('idn_to_ascii')) { $ascii = @idn_to_ascii($domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); if (is_string($ascii) && $ascii !== '') { return $ascii; } } return $domain; } } 