Skip to content

Commit

Permalink
Added method for getting contact by type in InfoDomainResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
struzik-vladislav committed Apr 27, 2022
1 parent 698157b commit 0b261ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Response/Domain/InfoDomainResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Struzik\EPPClient\Response\Domain;

use Struzik\EPPClient\Response\CommonResponse;
use XPath;

/**
* Object representation of the response of domain information command.
Expand Down Expand Up @@ -73,6 +74,20 @@ public function getContacts(): array
return array_combine(array_column($contacts, 'type'), array_column($contacts, 'nichandle'));
}

/**
* Nichandle of the domain contact by type.
*/
public function getContactByType(string $type): ?string
{
$pattern = '//epp:epp/epp:response/epp:resData/domain:infData/domain:contact[php:functionString("XPath\quote", @type) = \'%s\']';
$node = $this->getFirst(sprintf($pattern, XPath\quote($type)));
if ($node === null) {
return null;
}

return $node->nodeValue;
}

/**
* List of domain nameservers.
*
Expand Down
3 changes: 3 additions & 0 deletions tests/Response/Domain/InfoDomainResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public function testInfo(): void
$this->assertTrue($response->statusExist(DomainStatusNode::STATUS_CLIENT_HOLD));
$this->assertFalse($response->statusExist(DomainStatusNode::STATUS_OK));
$this->assertSame('example-contact-id', $response->getRegistrant());
$this->assertSame('example-contact-id', $response->getContactByType(DomainContactNode::TYPE_ADMIN));
$this->assertSame('example-contact-id', $response->getContactByType(DomainContactNode::TYPE_BILLING));
$this->assertSame('example-contact-id', $response->getContactByType(DomainContactNode::TYPE_TECH));
$this->assertSame([DomainContactNode::TYPE_ADMIN => 'example-contact-id', DomainContactNode::TYPE_BILLING => 'example-contact-id', DomainContactNode::TYPE_TECH => 'example-contact-id'], $response->getContacts());
$this->assertSame(['ns1.example.com', 'ns2.example.com', 'ns3.example.com'], $response->getNameservers());
$this->assertSame(['host1.example.com', 'host2.example.com'], $response->getHosts());
Expand Down

0 comments on commit 0b261ff

Please sign in to comment.