Skip to content

Commit

Permalink
retreval fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
antedebaas committed Jul 12, 2024
1 parent 64c9d54 commit d3d045c
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/Records/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
4 changes: 2 additions & 2 deletions src/TXTRecords/BIMI1.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class BIMI1 extends V {

public string $l;
public string $a;
protected string $l;
protected string $a;

function __construct(string $value)
{
Expand Down
4 changes: 2 additions & 2 deletions src/TXTRecords/DKIM1.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class DKIM1 extends V {

public string $k;
public string $p;
protected string $k;
protected string $p;

function __construct(string $value)
{
Expand Down
12 changes: 6 additions & 6 deletions src/TXTRecords/DMARC1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/TXTRecords/SPF1.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class SPF1 extends V {

public array $value;
protected array $value;

function __construct(string $value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/TXTRecords/STSV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class STSV1 extends V {

public int $id;
protected int $id;

function __construct(string $value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/TXTRecords/TLSRPTV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TLSRPTV1 extends V {

public array $rua;
protected array $rua;

function __construct(string $value)
{
Expand Down
48 changes: 44 additions & 4 deletions src/TXTRecords/V.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
<?php

namespace Spatie\Dns\TXTRecords;

use ReflectionClass;
use Spatie\Dns\Exceptions\InvalidArgument;
use Spatie\Macroable\Macroable;

abstract class V {
public string $type;
public string $version;
use Macroable {
__call as protected macroCall;
}

protected string $type;
protected string $version;

public function __construct(array $attributes)
{
$type = $attributes['type'] ?? null;
$expectedType = (new ReflectionClass($this))->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
{
Expand Down Expand Up @@ -32,5 +73,4 @@ protected function cast(string $attribute, $value)

return $value;
}

}

0 comments on commit d3d045c

Please sign in to comment.