1. Go to this page and download the library: Download estratos/namesilo-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Estratos\DomainApiInterface\Domain\DomainProviderInterface;
use Estratos\DomainApiInterface\Request\RegisterDomainRequest;
final class DomainController
{
public function register(DomainProviderInterface $domainProvider): void
{
$availability = $domainProvider->checkAvailability('example.com');
if (!$availability->isAvailable()) {
throw new \RuntimeException('Domain is not available.');
}
$result = $domainProvider->register(new RegisterDomainRequest(
domain: 'example.com',
years: 1,
contactId: '12345',
private: true,
autoRenew: true,
));
if (!$result->isSuccess()) {
throw new \RuntimeException($result->errorMessage ?? 'Registration failed.');
}
}
}
use Estratos\DomainApiInterface\DNS\DNSProviderInterface;
use Estratos\DomainApiInterface\Enum\RecordType;
use Estratos\DomainApiInterface\Request\AddDnsRecordRequest;
final class DnsController
{
public function addRecord(DNSProviderInterface $dnsProvider): void
{
$record = $dnsProvider->addRecord(new AddDnsRecordRequest(
domain: 'example.com',
host: 'www',
type: RecordType::A,
value: '192.0.2.1',
ttl: 3600,
));
}
}
use Estratos\DomainApiInterface\Account\AccountProviderInterface;
final class AccountController
{
public function balance(AccountProviderInterface $accountProvider): array
{
$balance = $accountProvider->getBalance();
return [
'balance' => $balance->balance,
'currency' => $balance->currency,
'available' => $balance->available,
];
}
}
use Estratos\NameSiloBundle\Event\DomainRegisteredEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class DomainSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
DomainRegisteredEvent::class => 'onDomainRegistered',
];
}
public function onDomainRegistered(DomainRegisteredEvent $event): void
{
$domain = $event->getDomain();
$orderId = $event->getOrderId();
$expiresAt = $event->getExpirationDate();
}
}
use Estratos\DomainApiInterface\Request\RegisterDomainRequest;
use Estratos\NameSiloBundle\Exception\ApiException;
use Estratos\NameSiloBundle\Exception\AuthenticationException;
use Estratos\NameSiloBundle\Exception\InsufficientFundsException;
use Estratos\NameSiloBundle\Exception\InvalidDomainException;
use Estratos\NameSiloBundle\Exception\RateLimitException;
use Estratos\NameSiloBundle\Exception\TimeoutException;
use Estratos\NameSiloBundle\Exception\ValidationException;
$request = new RegisterDomainRequest(
domain: 'example.com',
years: 1,
contactId: '12345',
);
try {
$result = $domainProvider->register($request);
} catch (AuthenticationException $e) {
// Invalid API key or IP not allowed.
} catch (InsufficientFundsException $e) {
// $e->getRequiredAmount(), $e->getAvailableBalance()
} catch (InvalidDomainException $e) {
// $e->getErrors()
} catch (RateLimitException $e) {
// $e->getRetryAfter()
} catch (TimeoutException $e) {
// $e->getTimeout()
} catch (ValidationException $e) {
// $e->getErrors()
} catch (ApiException $e) {
// $e->getEndpoint(), $e->getStatusCode(), $e->getApiCode(), $e->getRequestId()
}