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