From d3d045c1aed61f8f152d11651eda11e069428f63 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Fri, 12 Jul 2024 18:05:58 +0200 Subject: [PATCH] retreval fixes --- src/Records/Record.php | 7 ++++++ src/TXTRecords/BIMI1.php | 4 ++-- src/TXTRecords/DKIM1.php | 4 ++-- src/TXTRecords/DMARC1.php | 12 +++++----- src/TXTRecords/SPF1.php | 2 +- src/TXTRecords/STSV1.php | 2 +- src/TXTRecords/TLSRPTV1.php | 2 +- src/TXTRecords/V.php | 48 +++++++++++++++++++++++++++++++++---- 8 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/Records/Record.php b/src/Records/Record.php index b2662ea..016e7f8 100644 --- a/src/Records/Record.php +++ b/src/Records/Record.php @@ -148,4 +148,11 @@ protected function castType(string $value): string { return mb_strtoupper($value); } + + protected function castV(string $value): object + { + preg_match('/v=([a-zA-Z0-9]+);?\W(.*)/', $value, $matches); + $v = "Spatie\\Dns\\TXTRecords\\".mb_strtoupper($matches[1]); + return new $v($matches[2]); + } } diff --git a/src/TXTRecords/BIMI1.php b/src/TXTRecords/BIMI1.php index 30ef337..f5c8aad 100644 --- a/src/TXTRecords/BIMI1.php +++ b/src/TXTRecords/BIMI1.php @@ -4,8 +4,8 @@ class BIMI1 extends V { - public string $l; - public string $a; + protected string $l; + protected string $a; function __construct(string $value) { diff --git a/src/TXTRecords/DKIM1.php b/src/TXTRecords/DKIM1.php index 04e2868..64817b7 100644 --- a/src/TXTRecords/DKIM1.php +++ b/src/TXTRecords/DKIM1.php @@ -4,8 +4,8 @@ class DKIM1 extends V { - public string $k; - public string $p; + protected string $k; + protected string $p; function __construct(string $value) { diff --git a/src/TXTRecords/DMARC1.php b/src/TXTRecords/DMARC1.php index fe9c839..942ee95 100644 --- a/src/TXTRecords/DMARC1.php +++ b/src/TXTRecords/DMARC1.php @@ -4,12 +4,12 @@ class DMARC1 extends V { - public string $p; - public array $rua; - public array $ruf; - public string $sp; - public int $pct; - public string $fo; + protected string $p; + protected array $rua; + protected array $ruf; + protected string $sp; + protected int $pct; + protected string $fo; function __construct(string $value) { diff --git a/src/TXTRecords/SPF1.php b/src/TXTRecords/SPF1.php index 84a7937..68dbe22 100644 --- a/src/TXTRecords/SPF1.php +++ b/src/TXTRecords/SPF1.php @@ -4,7 +4,7 @@ class SPF1 extends V { - public array $value; + protected array $value; function __construct(string $value) { diff --git a/src/TXTRecords/STSV1.php b/src/TXTRecords/STSV1.php index f23afd2..c06b77c 100644 --- a/src/TXTRecords/STSV1.php +++ b/src/TXTRecords/STSV1.php @@ -4,7 +4,7 @@ class STSV1 extends V { - public int $id; + protected int $id; function __construct(string $value) { diff --git a/src/TXTRecords/TLSRPTV1.php b/src/TXTRecords/TLSRPTV1.php index 1199d8c..4ef6d05 100644 --- a/src/TXTRecords/TLSRPTV1.php +++ b/src/TXTRecords/TLSRPTV1.php @@ -4,7 +4,7 @@ class TLSRPTV1 extends V { - public array $rua; + protected array $rua; function __construct(string $value) { diff --git a/src/TXTRecords/V.php b/src/TXTRecords/V.php index 79bc3a3..21ec8d4 100644 --- a/src/TXTRecords/V.php +++ b/src/TXTRecords/V.php @@ -1,10 +1,51 @@ getShortName(); + + if ($type !== $expectedType) { + throw InvalidArgument::wrongRecordType($type, $expectedType); + } + + foreach ($attributes as $key => $value) { + $key = str_replace('-', '_', $key); + + if (property_exists($this, $key)) { + $return = $this->cast($key, $value); + if(is_array($return)){ + foreach($return as $key => $subvalue){ + $this->$key = $subvalue; + } + } else { + $this->$key = $return; + } + } + } + } + + public function __call(string $name, array $arguments) + { + if (property_exists($this, $name)) { + return $this->$name; + } + + return $this->macroCall($name, $arguments); + } protected function prepareInt($value): int { @@ -32,5 +73,4 @@ protected function cast(string $attribute, $value) return $value; } - } \ No newline at end of file