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
|
|
|
abstract class Entity implements \JsonSerializable |
16
|
|
|
{ |
17
|
|
|
private const STATUS_PENDING = 'pending'; |
18
|
|
|
private const STATUS_VALID = 'valid'; |
19
|
|
|
private const STATUS_READY = 'ready'; |
20
|
|
|
private const STATUS_INVALID = 'invalid'; |
21
|
|
|
private const STATUS_PROCESSING = 'processing'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $status; |
27
|
|
|
|
28
|
|
|
public function __construct(array $data) |
29
|
|
|
{ |
30
|
|
|
foreach ($data as $key => $value) { |
31
|
|
|
if (property_exists($this, $key)) { |
32
|
|
|
$this->{$key} = $value; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function isInvalid(): bool |
38
|
|
|
{ |
39
|
|
|
return $this->status === self::STATUS_INVALID; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function isValid(): bool |
43
|
|
|
{ |
44
|
|
|
return $this->status === self::STATUS_VALID; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function isPending(): bool |
48
|
|
|
{ |
49
|
|
|
return $this->status === self::STATUS_PENDING; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function isReady(): bool |
53
|
|
|
{ |
54
|
|
|
return $this->status === self::STATUS_READY; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function isProcessing(): bool |
58
|
|
|
{ |
59
|
|
|
return $this->status === self::STATUS_PROCESSING; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function jsonSerialize(): array |
63
|
|
|
{ |
64
|
|
|
$reflect = new \ReflectionClass($this); |
65
|
|
|
|
66
|
|
|
$output = []; |
67
|
|
|
foreach ($reflect->getProperties() as $property) { |
68
|
|
|
$property->setAccessible(true); |
69
|
|
|
$output[$property->getName()] = $property->getValue($this); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $output; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|