diff --git a/src/Service/Connector/NamecheapConnector.php b/src/Service/Connector/NamecheapConnector.php index 2c5b55e..80ce488 100644 --- a/src/Service/Connector/NamecheapConnector.php +++ b/src/Service/Connector/NamecheapConnector.php @@ -4,6 +4,7 @@ namespace App\Service\Connector; use App\Entity\Domain; use Psr\Cache\CacheItemInterface; +use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\DependencyInjection\Attribute\Autoconfigure; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -14,8 +15,9 @@ class NamecheapConnector extends AbstractProvider public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response'; - public function __construct(private HttpClientInterface $client, private readonly string $outgoingIp) + public function __construct(CacheItemPoolInterface $cacheItemPool, private HttpClientInterface $client, private readonly string $outgoingIp) { + parent::__construct($cacheItemPool); } public function orderDomain(Domain $domain, $dryRun): void @@ -27,8 +29,8 @@ class NamecheapConnector extends AbstractProvider throw new \Exception('Namecheap account requires at least one address to purchase a domain'); } - $addressId = (string) $addresses->attributes()['AddressId']; - $address = (array) $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun)->GetAddressInfoResult; + $addressId = (string)$addresses->attributes()['AddressId']; + $address = (array)$this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun)->GetAddressInfoResult; if (empty($address['PostalCode'])) { $address['PostalCode'] = $address['Zip']; @@ -52,7 +54,7 @@ class NamecheapConnector extends AbstractProvider private static function mergePrefixKeys(string $prefix, array|object $src, array &$dest) { foreach ($src as $key => $value) { - $dest[$prefix.$key] = $value; + $dest[$prefix . $key] = $value; } } @@ -86,11 +88,19 @@ class NamecheapConnector extends AbstractProvider protected function getCachedTldList(): CacheItemInterface { - // TODO: Implement getCachedTldList() method. + return $this->cacheItemPool->getItem('app.provider.namecheap.supported-tld'); } protected function getSupportedTldList(): array { - // TODO: Implement getSupportedTldList() method. + $supported = []; + + $tlds = $this->call('namecheap.domains.gettldlist', [], false)->Tlds->Tld; + + for ($i = 0; $i < $tlds->count(); ++$i) { + $supported[] = (string) $tlds[$i]['Name']; + } + + return $supported; } }