1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rogierw\Letsencrypt\DTO; |
4
|
|
|
|
5
|
|
|
use Rogierw\Letsencrypt\Http\Response; |
6
|
|
|
use Rogierw\Letsencrypt\Support\Arr; |
7
|
|
|
use Rogierw\Letsencrypt\Support\Url; |
8
|
|
|
use Spatie\DataTransferObject\DataTransferObject; |
9
|
|
|
|
10
|
|
|
class OrderData extends DataTransferObject |
11
|
|
|
{ |
12
|
|
|
public $id; |
13
|
|
|
public $url; |
14
|
|
|
public $status; |
15
|
|
|
public $expires; |
16
|
|
|
public $identifiers; |
17
|
|
|
public $domainValidationUrls; |
18
|
|
|
public $finalizeUrl; |
19
|
|
|
public $accountUrl; |
20
|
|
|
public $certificateUrl; |
21
|
|
|
|
22
|
|
|
private $finalized = false; |
23
|
|
|
|
24
|
|
|
public static function fromResponse(Response $response, string $accountUrl = ''): self |
25
|
|
|
{ |
26
|
|
|
$url = Arr::get($response->getRawHeaders(), 'Location'); |
27
|
|
|
|
28
|
|
|
if (empty($url)) { |
29
|
|
|
$url = Arr::get($response->getHeaders(), 'url'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$url = trim(rtrim($url, '?')); |
33
|
|
|
|
34
|
|
|
return new self([ |
35
|
|
|
'id' => Url::extractId($url), |
36
|
|
|
'url' => $url, |
37
|
|
|
'status' => $response->getBody()['status'], |
38
|
|
|
'expires' => $response->getBody()['expires'], |
39
|
|
|
'identifiers' => $response->getBody()['identifiers'], |
40
|
|
|
'domainValidationUrls' => $response->getBody()['authorizations'], |
41
|
|
|
'finalizeUrl' => $response->getBody()['finalize'], |
42
|
|
|
'accountUrl' => $accountUrl, |
43
|
|
|
]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function setCertificateUrl(string $url): void |
47
|
|
|
{ |
48
|
|
|
$this->certificateUrl = $url; |
49
|
|
|
$this->finalized = true; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function isPending(): bool |
53
|
|
|
{ |
54
|
|
|
return $this->status === 'pending'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function isReady(): bool |
58
|
|
|
{ |
59
|
|
|
return $this->status === 'ready'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function isValid(): bool |
63
|
|
|
{ |
64
|
|
|
return $this->status === 'valid'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function isInvalid(): bool |
68
|
|
|
{ |
69
|
|
|
return $this->status === 'invalid'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function isFinalized() |
73
|
|
|
{ |
74
|
|
|
return $this->finalized; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function isNotFinalized() |
78
|
|
|
{ |
79
|
|
|
return !$this->finalized; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|