|
2 | 2 |
|
3 | 3 | namespace Vonage\Verify2\VerifyObjects;
|
4 | 4 |
|
5 |
| -use InvalidArgumentException; |
6 |
| - |
7 | 5 | class VerifyEvent
|
8 | 6 | {
|
9 |
| - private static array $mandatoryFields = [ |
10 |
| - 'request_id', |
11 |
| - 'triggered_at', |
12 |
| - 'type', |
13 |
| - 'channel', |
14 |
| - 'status', |
15 |
| - 'finalized_at', |
16 |
| - 'client_ref' |
17 |
| - ]; |
18 |
| - private string $requestId; |
19 |
| - private string $triggeredAt; |
20 |
| - private string $type; |
21 |
| - private string $channel; |
22 |
| - private string $status; |
23 |
| - private string $finalizedAt; |
24 |
| - private string $clientRef; |
| 7 | + private array $data; |
25 | 8 |
|
26 | 9 | public function __construct(array $data)
|
27 | 10 | {
|
28 |
| - foreach (static::$mandatoryFields as $key) { |
29 |
| - if (!array_key_exists($key, $data)) { |
30 |
| - throw new InvalidArgumentException('Verify Event missing required data `' . $key . '`'); |
31 |
| - } |
32 |
| - } |
33 |
| - |
34 |
| - $this->requestId = $data['request_id']; |
35 |
| - $this->triggeredAt = $data['triggered_at']; |
36 |
| - $this->type = $data['type']; |
37 |
| - $this->channel = $data['channel']; |
38 |
| - $this->status = $data['status']; |
39 |
| - $this->finalizedAt = $data['finalized_at']; |
40 |
| - $this->clientRef = $data['client_ref']; |
41 |
| - } |
42 |
| - |
43 |
| - public function getRequestId(): string |
44 |
| - { |
45 |
| - return $this->requestId; |
46 |
| - } |
47 |
| - |
48 |
| - public function setRequestId(string $requestId): VerifyEvent |
49 |
| - { |
50 |
| - $this->requestId = $requestId; |
51 |
| - |
52 |
| - return $this; |
53 |
| - } |
54 |
| - |
55 |
| - public function getTriggeredAt(): string |
56 |
| - { |
57 |
| - return $this->triggeredAt; |
58 |
| - } |
59 |
| - |
60 |
| - public function setTriggeredAt(string $triggeredAt): VerifyEvent |
61 |
| - { |
62 |
| - $this->triggeredAt = $triggeredAt; |
63 |
| - |
64 |
| - return $this; |
| 11 | + $this->data = $data; |
65 | 12 | }
|
66 | 13 |
|
67 |
| - public function getType(): string |
| 14 | + public function __get($property) |
68 | 15 | {
|
69 |
| - return $this->type; |
| 16 | + return $this->data[$property] ?? null; |
70 | 17 | }
|
71 | 18 |
|
72 |
| - public function setType(string $type): VerifyEvent |
| 19 | + public function __set($property, $value) |
73 | 20 | {
|
74 |
| - $this->type = $type; |
| 21 | + $this->data[$property] = $value; |
75 | 22 |
|
76 | 23 | return $this;
|
77 | 24 | }
|
78 | 25 |
|
79 |
| - public function getChannel(): string |
| 26 | + public function __isset(string $name): bool |
80 | 27 | {
|
81 |
| - return $this->channel; |
| 28 | + return isset($this->data[$name]); |
82 | 29 | }
|
83 | 30 |
|
84 |
| - public function setChannel(string $channel): VerifyEvent |
| 31 | + public function fromArray(array $data): static |
85 | 32 | {
|
86 |
| - $this->channel = $channel; |
| 33 | + $this->data = $data; |
87 | 34 |
|
88 | 35 | return $this;
|
89 | 36 | }
|
90 | 37 |
|
91 |
| - public function getStatus(): string |
| 38 | + public function toArray(): array |
92 | 39 | {
|
93 |
| - return $this->status; |
94 |
| - } |
95 |
| - |
96 |
| - public function setStatus(string $status): VerifyEvent |
97 |
| - { |
98 |
| - $this->status = $status; |
99 |
| - |
100 |
| - return $this; |
101 |
| - } |
102 |
| - |
103 |
| - public function getFinalizedAt(): string |
104 |
| - { |
105 |
| - return $this->finalizedAt; |
106 |
| - } |
107 |
| - |
108 |
| - public function setFinalizedAt(string $finalizedAt): VerifyEvent |
109 |
| - { |
110 |
| - $this->finalizedAt = $finalizedAt; |
111 |
| - |
112 |
| - return $this; |
113 |
| - } |
114 |
| - |
115 |
| - public function getClientRef(): string |
116 |
| - { |
117 |
| - return $this->clientRef; |
118 |
| - } |
119 |
| - |
120 |
| - public function setClientRef(string $clientRef): VerifyEvent |
121 |
| - { |
122 |
| - $this->clientRef = $clientRef; |
123 |
| - |
124 |
| - return $this; |
| 40 | + return $this->data; |
125 | 41 | }
|
126 | 42 | }
|
0 commit comments