remotelyliving /
php-dns
| 1 | <?php |
||
| 2 | |||
| 3 | namespace RemotelyLiving\PHPDNS\Mappers; |
||
| 4 | |||
| 5 | use RemotelyLiving\PHPDNS\Entities\DNSRecord; |
||
| 6 | use RemotelyLiving\PHPDNS\Entities\DNSRecordType; |
||
| 7 | use RemotelyLiving\PHPDNS\Entities\Hostname; |
||
| 8 | use RemotelyLiving\PHPDNS\Entities\Interfaces\DNSRecordInterface; |
||
| 9 | use RemotelyLiving\PHPDNS\Entities\IPAddress; |
||
| 10 | |||
| 11 | use function str_ireplace; |
||
| 12 | |||
| 13 | final class GoogleDNS extends MapperAbstract |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private const DATA = 'data'; |
||
| 19 | public function toDNSRecord(): DNSRecordInterface |
||
| 20 | { |
||
| 21 | $type = DNSRecordType::createFromInt((int) $this->fields['type']); |
||
| 22 | $IPAddress = (isset($this->fields[self::DATA]) && IPAddress::isValid($this->fields[self::DATA])) |
||
| 23 | ? $this->fields[self::DATA] |
||
| 24 | : null; |
||
| 25 | |||
| 26 | $value = (isset($this->fields[self::DATA]) && !$IPAddress) |
||
| 27 | ? str_ireplace('"', '', (string)$this->fields[self::DATA]) |
||
| 28 | : null; |
||
| 29 | |||
| 30 | return DNSRecord::createFromPrimitives( |
||
| 31 | (string)$type, |
||
| 32 | $this->fields['name'], |
||
| 33 | $this->fields['TTL'], |
||
| 34 | $IPAddress, |
||
| 35 | 'IN', |
||
| 36 | $value |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 37 | ); |
||
| 38 | } |
||
| 39 | } |
||
| 40 |