1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RemotelyLiving\PHPDNS\Resolvers; |
4
|
|
|
|
5
|
|
|
use RemotelyLiving\PHPDNS\Entities\DNSRecordCollection; |
6
|
|
|
use RemotelyLiving\PHPDNS\Entities\DNSRecordType; |
7
|
|
|
use RemotelyLiving\PHPDNS\Entities\Hostname; |
8
|
|
|
use RemotelyLiving\PHPDNS\Entities\IPAddress; |
9
|
|
|
use RemotelyLiving\PHPDNS\Mappers\LocalSystem as LocalMapper; |
10
|
|
|
use RemotelyLiving\PHPDNS\Resolvers\Interfaces\ReverseDNSQuery; |
11
|
|
|
use RemotelyLiving\PHPDNS\Services\Interfaces\LocalSystemDNS; |
12
|
|
|
use RemotelyLiving\PHPDNS\Services\LocalSystemDNS as LocalDNSService; |
13
|
|
|
|
14
|
|
|
final class LocalSystem extends ResolverAbstract implements ReverseDNSQuery |
15
|
|
|
{ |
16
|
|
|
private LocalSystemDNS $systemDNS; |
17
|
|
|
|
18
|
|
|
private LocalMapper $mapper; |
19
|
|
|
|
20
|
|
|
public function __construct(LocalSystemDNS $systemDNS = null, LocalMapper $mapper = null) |
21
|
|
|
{ |
22
|
|
|
$this->systemDNS = $systemDNS ?? new LocalDNSService(); |
23
|
|
|
$this->mapper = $mapper ?? new LocalMapper(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getHostnameByAddress(string $IPAddress): Hostname |
27
|
|
|
{ |
28
|
|
|
$result = $this->systemDNS->getHostnameByAddress((string)(new IPAddress($IPAddress))); |
29
|
|
|
|
30
|
|
|
return Hostname::createFromString($result); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function doQuery(Hostname $hostname, DNSRecordType $recordType): DNSRecordCollection |
34
|
|
|
{ |
35
|
|
|
$results = $this->systemDNS->getRecord( |
36
|
|
|
$hostname->getHostnameWithoutTrailingDot(), // dns_get_record doesn't like trailing dot as much! |
37
|
|
|
$this->mapper->getTypeCodeFromType($recordType) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$collection = new DNSRecordCollection(); |
41
|
|
|
|
42
|
|
|
foreach ($results as $result) { |
43
|
|
|
$collection[] = $this->mapper->mapFields($result)->toDNSRecord(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $collection; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|