Files
portal-api/app/Integrations/Whmcs/Support/RegistrarIdResolver.php
2026-09-09 16:56:22 +07:00

27 lines
816 B
PHP

<?php
namespace App\Integrations\Whmcs\Support;
use Illuminate\Support\Facades\DB;
/** Resolves a WHMCS registrar module slug (e.g. 'nhanhoa', 'PA') to the local `registrars.id`, matched case-insensitively on short_name. */
class RegistrarIdResolver
{
/** @var array<string, int>|null lowercase short_name => registrar id */
private static ?array $map = null;
public function resolve(string $whmcsRegistrar): ?int
{
$whmcsRegistrar = trim($whmcsRegistrar);
if ($whmcsRegistrar === '') {
return null;
}
self::$map ??= DB::table('registrars')->pluck('id', 'short_name')
->mapWithKeys(fn ($id, $shortName) => [mb_strtolower($shortName) => $id])
->all();
return self::$map[mb_strtolower($whmcsRegistrar)] ?? null;
}
}