-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,159 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
namespace RemotelyLiving\PHPDNS\Entities; | ||
|
||
use RemotelyLiving\PHPDNS\Entities\Interfaces\Arrayable; | ||
use RemotelyLiving\PHPDNS\Entities\Interfaces\Serializable; | ||
use RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException; | ||
|
||
abstract class DataAbstract implements Arrayable, Serializable | ||
{ | ||
abstract public function __toString(); | ||
|
||
public function equals(DataAbstract $dataAbstract): bool | ||
{ | ||
return (string)$this === (string)$dataAbstract; | ||
} | ||
|
||
public static function createFromTypeAndString(DNSRecordType $recordType, string $data): self | ||
{ | ||
if ($recordType->isA(DNSRecordType::TYPE_TXT)) { | ||
return new TXTData($data); | ||
} | ||
|
||
if ($recordType->isA(DNSRecordType::TYPE_MX)) { | ||
$exploded = explode(' ', $data); | ||
|
||
return new MXData(new Hostname($exploded[1]), (int)$exploded[0]); | ||
} | ||
|
||
if ($recordType->isA(DNSRecordType::TYPE_SOA)) { | ||
$exploded = explode(' ', $data); | ||
|
||
return new SOAData( | ||
new Hostname($exploded[0]), | ||
new Hostname($exploded[1]), | ||
(int)$exploded[2] ?? 0, | ||
(int)$exploded[3] ?? 0, | ||
(int)$exploded[4] ?? 0, | ||
(int)$exploded[5] ?? 0, | ||
(int)$exploded[6] ?? 0 | ||
); | ||
} | ||
|
||
if ($recordType->isA(DNSRecordType::TYPE_NS)) { | ||
return new NSData(new Hostname($data)); | ||
} | ||
|
||
throw new InvalidArgumentException("{$data} could not be created with type {$recordType}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.