1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the LetsEncrypt ACME client. |
7
|
|
|
* |
8
|
|
|
* @author Ivanov Aleksandr <[email protected]> |
9
|
|
|
* @copyright 2019-2020 |
10
|
|
|
* @license https://github.com/misantron/letsencrypt-client/blob/master/LICENSE MIT License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace LetsEncrypt\Entity; |
14
|
|
|
|
15
|
|
|
final class Order extends Entity |
16
|
|
|
{ |
17
|
|
|
use UrlAwareTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
public $expires; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Order identifiers. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $identifiers; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Authorization[] |
33
|
|
|
*/ |
34
|
|
|
protected $authorizations; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Order finalize URL. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $finalize; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Certificate request URL. |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $certificate; |
49
|
|
|
|
50
|
|
|
public function __construct(array $data, string $url) |
51
|
|
|
{ |
52
|
|
|
// extract only value from identifiers data |
53
|
|
|
$data['identifiers'] = array_map(static function (array $entry) { |
54
|
|
|
return $entry['value']; |
55
|
|
|
}, $data['identifiers']); |
56
|
|
|
|
57
|
|
|
parent::__construct($data); |
58
|
|
|
|
59
|
|
|
$this->url = $url; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function isIdentifiersEqual(array $subjects): bool |
63
|
|
|
{ |
64
|
|
|
$identifiers = $this->identifiers; |
65
|
|
|
|
66
|
|
|
sort($identifiers, SORT_STRING); |
67
|
|
|
sort($subjects, SORT_STRING); |
68
|
|
|
|
69
|
|
|
return $identifiers === $subjects; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return Authorization[] |
74
|
|
|
*/ |
75
|
|
|
public function getPendingAuthorizations(): array |
76
|
|
|
{ |
77
|
|
|
$authorizations = []; |
78
|
|
|
foreach ($this->authorizations as $authorization) { |
79
|
|
|
if ($authorization->isPending()) { |
80
|
|
|
$authorizations[] = $authorization; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $authorizations; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return Authorization[] |
89
|
|
|
*/ |
90
|
|
|
public function getAuthorizations(): array |
91
|
|
|
{ |
92
|
|
|
return $this->authorizations; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function allAuthorizationsValid(): bool |
96
|
|
|
{ |
97
|
|
|
foreach ($this->authorizations as $authorization) { |
98
|
|
|
if (!$authorization->isValid()) { |
99
|
|
|
return false; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return true; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getIdentifiers(): array |
107
|
|
|
{ |
108
|
|
|
return $this->identifiers; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getFinalizeUrl(): string |
112
|
|
|
{ |
113
|
|
|
return $this->finalize; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getCertificateRequestUrl(): string |
117
|
|
|
{ |
118
|
|
|
return $this->certificate; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|