1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rogierw\Letsencrypt\DTO; |
4
|
|
|
|
5
|
|
|
use Rogierw\Letsencrypt\Endpoints\DomainValidation; |
6
|
|
|
use Rogierw\Letsencrypt\Http\Response; |
7
|
|
|
use Rogierw\Letsencrypt\Support\Arr; |
8
|
|
|
use Spatie\DataTransferObject\DataTransferObject; |
9
|
|
|
|
10
|
|
|
class DomainValidationData extends DataTransferObject |
11
|
|
|
{ |
12
|
|
|
public $identifier; |
13
|
|
|
public $status; |
14
|
|
|
public $expires; |
15
|
|
|
public $file; |
16
|
|
|
public $dns; |
17
|
|
|
public $validationRecord; |
18
|
|
|
|
19
|
|
|
public static function fromResponse(Response $response): self |
20
|
|
|
{ |
21
|
|
|
return new self([ |
22
|
|
|
'identifier' => $response->getBody()['identifier'], |
23
|
|
|
'status' => $response->getBody()['status'], |
24
|
|
|
'expires' => $response->getBody()['expires'], |
25
|
|
|
'file' => self::getValidationByType($response->getBody()['challenges'], DomainValidation::TYPE_HTTP), |
26
|
|
|
'dns' => self::getValidationByType($response->getBody()['challenges'], DomainValidation::TYPE_DNS), |
27
|
|
|
'validationRecord' => Arr::get($response->getBody(), 'validationRecord', []), |
28
|
|
|
]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private static function getValidationByType(array $haystack, string $type): array |
32
|
|
|
{ |
33
|
|
|
foreach ($haystack as $key => $data) { |
34
|
|
|
if ($data['type'] === $type) { |
35
|
|
|
return $haystack[$key]; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return []; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function isPending(): bool |
43
|
|
|
{ |
44
|
|
|
return $this->status === 'pending'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function isValid(): bool |
48
|
|
|
{ |
49
|
|
|
return $this->status === 'valid'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function isInvalid(): bool |
53
|
|
|
{ |
54
|
|
|
return $this->status === 'invalid'; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|