1. Go to this page and download the library: Download hostmaster/ua 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/ */
hostmaster / ua example snippets
use Hostmaster\Ua\Client;
use Hostmaster\Ua\Config;
use Hostmaster\Ua\Enum\ContactType;
use Hostmaster\Ua\Enum\PostalType;
use Hostmaster\Ua\Model\Address;
use Hostmaster\Ua\Model\AuthInfo;
use Hostmaster\Ua\Model\ContactCreate;
use Hostmaster\Ua\Model\DomainContact;
use Hostmaster\Ua\Model\DomainCreate;
use Hostmaster\Ua\Model\Nameserver;
use Hostmaster\Ua\Model\Period;
use Hostmaster\Ua\Model\PostalInfo;
$client = new Client(new Config(
username: 'MYREG',
password: 'super-secret',
// host: 'epp-test.hostmaster.ua', // OT&E
// localCert: '/etc/ssl/registrar.pem',
// localPk: '/etc/ssl/registrar.key',
));
$client->login();
$results = $client->domain->check(['example.ua', 'example2.ua']);
foreach ($results as $r) {
printf("%s -> %s%s\n", $r->name, $r->available ? 'free' : 'taken',
$r->reason ? " ({$r->reason})" : '');
}
$client->contact->create(new ContactCreate(
id: 'CT-EXAMPLE',
postalInfo: [
new PostalInfo(
type: PostalType::International,
name: 'John Doe',
address: new Address(
street: ['10 Khreshchatyk St'],
city: 'Kyiv',
countryCode: 'UA',
postalCode: '01001',
),
),
],
email: '[email protected]',
authInfo: new AuthInfo('contact-secret'),
));
$client->domain->create(new DomainCreate(
name: 'example.ua',
registrant: 'CT-EXAMPLE',
period: new Period(1),
nameservers: [
Nameserver::reference('ns1.example.com'),
Nameserver::reference('ns2.example.com'),
],
contacts: [
new DomainContact('CT-EXAMPLE', ContactType::Admin),
new DomainContact('CT-EXAMPLE', ContactType::Tech),
],
authInfo: new AuthInfo('domain-secret'),
license: 'A0000000', // optional uaepp:license extension
));
$client->logout();
use Hostmaster\Ua\Exception\AuthenticationException;
use Hostmaster\Ua\Exception\BillingException;
use Hostmaster\Ua\Exception\ObjectExistsException;
use Hostmaster\Ua\Exception\ObjectNotFoundException;
use Hostmaster\Ua\Exception\EppException;
use Hostmaster\Ua\Exception\ConnectionException;
try {
$client->login();
$client->domain->create($req);
} catch (AuthenticationException $e) {
// 2200/2501 — bad credentials
} catch (ObjectExistsException $e) {
// 2302 — domain already registered
} catch (BillingException $e) {
// 2104 — registrar balance is negative
} catch (EppException $e) {
// any other 2xxx — inspect $e->resultCode, $e->reasons, $e->svTRID
} catch (ConnectionException $e) {
// network/TLS failure
}
$client = new Client($config, new \Monolog\Logger('epp'));
use Hostmaster\Ua\Logging\RedactingLogger;
$logger = new RedactingLogger(new \Monolog\Logger('epp'));
$client = new Client($config, $logger);
$logger->info('paying invoice', ['xml' => $rawXml]); // 'xml' value is sanitised on its way out
while (($msg = $client->poll->request()) !== null) {
echo "[{$msg->id}] {$msg->message}\n";
// $msg->response gives access to <resData> / <extension> for typed parsing
$client->poll->acknowledge($msg->id);
}
use Hostmaster\Ua\Notification\EmailNotificationParser;
use Hostmaster\Ua\Enum\EmailTemplate;
$notification = EmailNotificationParser::parseRaw($rawEmail);
if ($notification->template === EmailTemplate::ObjectNew
&& $notification->objectType === 'DOMAIN') {
$repo->markCreated($notification->objectName, $notification->roid);
}
// Or when your MTA already gave you an array of headers (e.g. from a webhook):
$n = EmailNotificationParser::fromHeaders($headersArray, $body);
// Sanity check before parsing:
if (EmailNotificationParser::isRegistryNotification($headersArray)) {
// … process …
}