Skip to content

Commit

Permalink
Recreated GetDomainResponse, based on the Response base class
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc committed Oct 17, 2024
1 parent 01ba813 commit 00568a1
Showing 1 changed file with 95 additions and 43 deletions.
138 changes: 95 additions & 43 deletions src/Responses/GetDomainResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,114 @@

use SimpleXMLElement;

class GetDomainResponse
class GetDomainResponse extends Response
{
public string $sld;

public string $tld;

public string $statusCode;

public string $statusText;

public array $licensee;
public array $admin;
public array $onSite;
public string $dnsType;

public array $dnsServers;

public array $dnsList;
public array $dnsIpList;

public string $authKey;

public bool $transferLock;

public \Carbon $expiration;

public \Carbon $renewlDeadline;

public \Carbon $registrationISO;

public string $expiration;
public string $renewalDeadline;
public string $registrationISO;
public string $extendType;

public bool $trustee;

public function __construct(SimpleXMLElement $element)
public array $dnssecRecords = [];
public string $orderID;
public ?string $label;
public ?string $notes;

/**
* Parse the result data from the XML.
*
* @param SimpleXMLElement $result
* @return self
*/
protected function parseResult(SimpleXMLElement $result): self
{
$this->tld = (string)$element->Result->TLD;

$this->sld = (string)$element->Result->SLD;

$this->statusCode = (string)$element->Result->StatusCode;

$this->statusText = (string)$element->Result->StatusText;

$this->dnsType = (string)$element->Result->DNSType;

$this->authKey = (string)$element->Result->AuthKey;

$this->trustee = ( (string)$element->Result->Trustee == "true" );

$this->transferLock = ( (string)$element->Result->TransferLock == "true");

$this->expiration = \Carbon::parseFromLocale( (string)$element->Result->Expiration );

$this->renewlDeadline = \Carbon::parseFromLocale( (string)$element->Result->RenewalDeadline );

$this->registrationISO = \Carbon::parseFromLocale( (string)$element->Result->RegistrationISO );
$this->sld = (string) $result->SLD;
$this->tld = (string) $result->TLD;
$this->statusCode = (string) $result->StatusCode;
$this->statusText = (string) $result->StatusText;

// Parse Licensee, Admin, and OnSite contacts
$this->licensee = $this->parseContact($result->Licensee);
$this->admin = $this->parseContact($result->Admin);
$this->onSite = $this->parseContact($result->OnSite);

// DNS and related data
$this->dnsType = (string) $result->DNSType;
$this->dnsList = explode(',', (string) $result->DNSList);
$this->dnsIpList = explode(',', (string) $result->DNSIPList);
$this->authKey = (string) $result->AuthKey;
$this->transferLock = (string) $result->TransferLock === 'true';
$this->expiration = (string) $result->Expiration;
$this->renewalDeadline = (string) $result->RenewalDeadline;
$this->registrationISO = (string) $result->RegistrationISO;
$this->extendType = (string) $result->ExtendType;
$this->trustee = (string) $result->Trustee === 'false';

// Parse DNSSEC records
if (property_exists($result, 'DNSSec')) {
foreach ($result->DNSSec->children() as $dnssecRecord) {
$this->dnssecRecords[] = $this->parseDnssecRecord($dnssecRecord);
}
}

$this->orderID = (string) $result->OrderID;
$this->label = (string) $result->Label ?? null;
$this->notes = (string) $result->Notes ?? null;

return $this;
}

$this->dnsServers = explode(",", (string)$element->Result->DNSList );
/**
* Parse contact details from Licensee, Admin, or OnSite fields.
*
* @param SimpleXMLElement $contact
* @return array
*/
protected function parseContact(SimpleXMLElement $contact): array
{
return [
'contactNr' => (string) $contact->ContactNr,
'firstName' => (string) $contact->FirstName,
'lastName' => (string) $contact->LastName,
'company' => (string) $contact->Company,
'street' => (string) $contact->Street,
'streetNr' => (string) $contact->StreetNr,
'postcode' => (string) $contact->Postcode,
'residence' => (string) $contact->Residence,
'country' => (string) $contact->Country,
'phone' => (string) $contact->Phone,
'email' => (string) $contact->EMail,
'vatNumber' => (string) $contact->VATNumber ?? null,
'language' => (string) $contact->Language,
];
}

$this->dnsIpList = explode( ",", (string)$element->Result->DNSIPList );
/**
* Parse a DNSSEC record from the XML.
*
* @param SimpleXMLElement $dnssecRecord
* @return array
*/
protected function parseDnssecRecord(SimpleXMLElement $dnssecRecord): array
{
return [
'keytag' => (string) $dnssecRecord->Keytag,
'algorithm' => (string) $dnssecRecord->Algorithm,
'algorithmString' => (string) $dnssecRecord->AlgorithmString,
'publicKey' => (string) $dnssecRecord->PublicKey,
'digest' => (string) $dnssecRecord->Digest,
'digestType' => (string) $dnssecRecord->DigestType,
];
}
}

0 comments on commit 00568a1

Please sign in to comment.