@@ 9-101 (lines=93) @@ | ||
6 | use DateTimeInterface; |
|
7 | use DateTimeZone; |
|
8 | ||
9 | final class Certificate |
|
10 | { |
|
11 | /** |
|
12 | * @var Id |
|
13 | */ |
|
14 | private $id; |
|
15 | ||
16 | /** |
|
17 | * @var DateTimeInterface |
|
18 | */ |
|
19 | private $created; |
|
20 | ||
21 | /** |
|
22 | * @var DateTimeInterface |
|
23 | */ |
|
24 | private $updated; |
|
25 | ||
26 | /** |
|
27 | * @var string |
|
28 | */ |
|
29 | private $certificate; |
|
30 | ||
31 | /** |
|
32 | * @string |
|
33 | */ |
|
34 | private function __construct(string $certificate) |
|
35 | { |
|
36 | $this->certificate = $certificate; |
|
37 | } |
|
38 | ||
39 | /** |
|
40 | * @param string $certificate |
|
41 | * @return Certificate |
|
42 | */ |
|
43 | public static function fromString(string $certificate) |
|
44 | { |
|
45 | return new self($certificate); |
|
46 | } |
|
47 | ||
48 | /** |
|
49 | * @param array $value |
|
50 | * @return Certificate |
|
51 | */ |
|
52 | public static function fromArray($value) |
|
53 | { |
|
54 | $timezone = new DateTimeZone('UTC'); |
|
55 | $cert = new Certificate($value['certificate_chain']); |
|
56 | $cert->id = Id::fromInteger(intval($value['id'])); |
|
57 | $cert->created = new DateTimeImmutable($value['created'], $timezone); |
|
58 | $cert->updated = new DateTimeImmutable($value['updated'], $timezone); |
|
59 | return $cert; |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * @return Id |
|
64 | */ |
|
65 | public function id(): Id |
|
66 | { |
|
67 | return $this->id; |
|
68 | } |
|
69 | ||
70 | /** |
|
71 | * @return DateTimeInterface |
|
72 | */ |
|
73 | public function created(): DateTimeInterface |
|
74 | { |
|
75 | return $this->created; |
|
76 | } |
|
77 | ||
78 | /** |
|
79 | * @return DateTimeInterface |
|
80 | */ |
|
81 | public function updated(): DateTimeInterface |
|
82 | { |
|
83 | return $this->updated; |
|
84 | } |
|
85 | ||
86 | /** |
|
87 | * @return string |
|
88 | */ |
|
89 | public function certificate(): string |
|
90 | { |
|
91 | return $this->certificate; |
|
92 | } |
|
93 | ||
94 | /** |
|
95 | * @return string |
|
96 | */ |
|
97 | public function __toString() |
|
98 | { |
|
99 | return $this->certificate; |
|
100 | } |
|
101 | } |
|
102 |
@@ 9-85 (lines=77) @@ | ||
6 | use DateTimeInterface; |
|
7 | use DateTimeZone; |
|
8 | ||
9 | final class Token |
|
10 | { |
|
11 | /** |
|
12 | * @var Id |
|
13 | */ |
|
14 | private $id; |
|
15 | ||
16 | /** |
|
17 | * @var DateTimeInterface |
|
18 | */ |
|
19 | private $created; |
|
20 | ||
21 | /** |
|
22 | * @var DateTimeInterface |
|
23 | */ |
|
24 | private $updated; |
|
25 | ||
26 | /** |
|
27 | * @var string |
|
28 | */ |
|
29 | private $token; |
|
30 | ||
31 | /** |
|
32 | * @param array $token |
|
33 | * @return Token |
|
34 | */ |
|
35 | public static function fromArray(array $token) |
|
36 | { |
|
37 | $timezone = new DateTimeZone('UTC'); |
|
38 | $t = new Token(); |
|
39 | $t->id = Id::fromInteger(intval($token['id'])); |
|
40 | $t->created = new DateTimeImmutable($token['created'], $timezone); |
|
41 | $t->updated = new DateTimeImmutable($token['updated'], $timezone); |
|
42 | $t->token = $token['token']; |
|
43 | return $t; |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * @return Id |
|
48 | */ |
|
49 | public function id(): Id |
|
50 | { |
|
51 | return $this->id; |
|
52 | } |
|
53 | ||
54 | /** |
|
55 | * @return DateTimeInterface |
|
56 | */ |
|
57 | public function created(): DateTimeInterface |
|
58 | { |
|
59 | return $this->created; |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * @return DateTimeInterface |
|
64 | */ |
|
65 | public function updated(): DateTimeInterface |
|
66 | { |
|
67 | return $this->updated; |
|
68 | } |
|
69 | ||
70 | /** |
|
71 | * @return string |
|
72 | */ |
|
73 | public function token(): string |
|
74 | { |
|
75 | return $this->token; |
|
76 | } |
|
77 | ||
78 | /** |
|
79 | * @return string |
|
80 | */ |
|
81 | public function __toString() |
|
82 | { |
|
83 | return $this->token(); |
|
84 | } |
|
85 | } |
|
86 |