|
12 | 12 | /**
|
13 | 13 | * Standardized response from sending a message
|
14 | 14 | */
|
15 |
| -class MessageSentReport implements \JsonSerializable { |
16 |
| - |
17 |
| - /** |
18 |
| - * @var boolean |
19 |
| - */ |
20 |
| - protected $success; |
21 |
| - |
22 |
| - /** |
23 |
| - * @var RequestInterface |
24 |
| - */ |
25 |
| - protected $request; |
26 |
| - |
27 |
| - /** |
28 |
| - * @var ResponseInterface | null |
29 |
| - */ |
30 |
| - protected $response; |
31 |
| - |
32 |
| - /** |
33 |
| - * @var string |
34 |
| - */ |
35 |
| - protected $reason; |
36 |
| - |
37 |
| - /** |
38 |
| - * @param RequestInterface $request |
39 |
| - * @param ResponseInterface $response |
40 |
| - * @param bool $success |
41 |
| - * @param string $reason |
42 |
| - */ |
43 |
| - public function __construct(RequestInterface $request, ?ResponseInterface $response = null, bool $success = true, $reason = 'OK') { |
| 15 | +class MessageSentReport implements \JsonSerializable |
| 16 | +{ |
| 17 | + |
| 18 | + /** |
| 19 | + * @var boolean |
| 20 | + */ |
| 21 | + protected $success; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var RequestInterface |
| 25 | + */ |
| 26 | + protected $request; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var ResponseInterface | null |
| 30 | + */ |
| 31 | + protected $response; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var string |
| 35 | + */ |
| 36 | + protected $reason; |
| 37 | + |
| 38 | + /** |
| 39 | + * @param RequestInterface $request |
| 40 | + * @param ResponseInterface $response |
| 41 | + * @param bool $success |
| 42 | + * @param string $reason |
| 43 | + */ |
| 44 | + public function __construct(RequestInterface $request, ?ResponseInterface $response = null, bool $success = true, $reason = 'OK') |
| 45 | + { |
44 | 46 | $this->request = $request;
|
45 | 47 | $this->response = $response;
|
46 |
| - $this->success = $success; |
47 |
| - $this->reason = $reason; |
48 |
| - } |
49 |
| - |
50 |
| - /** |
51 |
| - * @return bool |
52 |
| - */ |
53 |
| - public function isSuccess(): bool { |
54 |
| - return $this->success; |
55 |
| - } |
56 |
| - |
57 |
| - /** |
58 |
| - * @param bool $success |
59 |
| - * |
60 |
| - * @return MessageSentReport |
61 |
| - */ |
62 |
| - public function setSuccess(bool $success): MessageSentReport { |
63 |
| - $this->success = $success; |
64 |
| - return $this; |
65 |
| - } |
66 |
| - |
67 |
| - /** |
68 |
| - * @return RequestInterface |
69 |
| - */ |
70 |
| - public function getRequest(): RequestInterface { |
71 |
| - return $this->request; |
72 |
| - } |
73 |
| - |
74 |
| - /** |
75 |
| - * @param RequestInterface $request |
76 |
| - * |
77 |
| - * @return MessageSentReport |
78 |
| - */ |
79 |
| - public function setRequest(RequestInterface $request): MessageSentReport { |
80 |
| - $this->request = $request; |
81 |
| - return $this; |
82 |
| - } |
83 |
| - |
84 |
| - /** |
85 |
| - * @return ResponseInterface | null |
86 |
| - */ |
87 |
| - public function getResponse(): ?ResponseInterface { |
88 |
| - return $this->response; |
89 |
| - } |
90 |
| - |
91 |
| - /** |
92 |
| - * @param ResponseInterface $response |
93 |
| - * |
94 |
| - * @return MessageSentReport |
95 |
| - */ |
96 |
| - public function setResponse(ResponseInterface $response): MessageSentReport { |
97 |
| - $this->response = $response; |
98 |
| - return $this; |
99 |
| - } |
100 |
| - |
101 |
| - /** |
102 |
| - * @return string |
103 |
| - */ |
104 |
| - public function getEndpoint(): string { |
105 |
| - return $this->request->getUri()->__toString(); |
106 |
| - } |
107 |
| - |
108 |
| - /** |
109 |
| - * @return bool |
110 |
| - */ |
111 |
| - public function isSubscriptionExpired(): bool { |
112 |
| - if (!$this->response) { |
113 |
| - return false; |
114 |
| - } |
115 |
| - |
116 |
| - return \in_array($this->response->getStatusCode(), [404, 410], true); |
117 |
| - } |
118 |
| - |
119 |
| - /** |
120 |
| - * @return string |
121 |
| - */ |
122 |
| - public function getReason(): string { |
123 |
| - return $this->reason; |
124 |
| - } |
125 |
| - |
126 |
| - /** |
127 |
| - * @param string $reason |
128 |
| - * |
129 |
| - * @return MessageSentReport |
130 |
| - */ |
131 |
| - public function setReason(string $reason): MessageSentReport { |
132 |
| - $this->reason = $reason; |
133 |
| - return $this; |
134 |
| - } |
135 |
| - |
136 |
| - /** |
137 |
| - * @return string |
138 |
| - */ |
139 |
| - public function getRequestPayload(): string { |
140 |
| - return $this->request->getBody()->getContents(); |
141 |
| - } |
142 |
| - |
143 |
| - /** |
144 |
| - * @return string | null |
145 |
| - */ |
146 |
| - public function getResponseContent(): ?string { |
| 48 | + $this->success = $success; |
| 49 | + $this->reason = $reason; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @return bool |
| 54 | + */ |
| 55 | + public function isSuccess(): bool |
| 56 | + { |
| 57 | + return $this->success; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @param bool $success |
| 62 | + * |
| 63 | + * @return MessageSentReport |
| 64 | + */ |
| 65 | + public function setSuccess(bool $success): MessageSentReport |
| 66 | + { |
| 67 | + $this->success = $success; |
| 68 | + return $this; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @return RequestInterface |
| 73 | + */ |
| 74 | + public function getRequest(): RequestInterface |
| 75 | + { |
| 76 | + return $this->request; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @param RequestInterface $request |
| 81 | + * |
| 82 | + * @return MessageSentReport |
| 83 | + */ |
| 84 | + public function setRequest(RequestInterface $request): MessageSentReport |
| 85 | + { |
| 86 | + $this->request = $request; |
| 87 | + return $this; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @return ResponseInterface | null |
| 92 | + */ |
| 93 | + public function getResponse(): ?ResponseInterface |
| 94 | + { |
| 95 | + return $this->response; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * @param ResponseInterface $response |
| 100 | + * |
| 101 | + * @return MessageSentReport |
| 102 | + */ |
| 103 | + public function setResponse(ResponseInterface $response): MessageSentReport |
| 104 | + { |
| 105 | + $this->response = $response; |
| 106 | + return $this; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * @return string |
| 111 | + */ |
| 112 | + public function getEndpoint(): string |
| 113 | + { |
| 114 | + return $this->request->getUri()->__toString(); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * @return bool |
| 119 | + */ |
| 120 | + public function isSubscriptionExpired(): bool |
| 121 | + { |
| 122 | + if (!$this->response) { |
| 123 | + return false; |
| 124 | + } |
| 125 | + |
| 126 | + return \in_array($this->response->getStatusCode(), [404, 410], true); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * @return string |
| 131 | + */ |
| 132 | + public function getReason(): string |
| 133 | + { |
| 134 | + return $this->reason; |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * @param string $reason |
| 139 | + * |
| 140 | + * @return MessageSentReport |
| 141 | + */ |
| 142 | + public function setReason(string $reason): MessageSentReport |
| 143 | + { |
| 144 | + $this->reason = $reason; |
| 145 | + return $this; |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * @return string |
| 150 | + */ |
| 151 | + public function getRequestPayload(): string |
| 152 | + { |
| 153 | + return $this->request->getBody()->getContents(); |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * @return string | null |
| 158 | + */ |
| 159 | + public function getResponseContent(): ?string |
| 160 | + { |
147 | 161 | if (!$this->response) {
|
148 | 162 | return null;
|
149 | 163 | }
|
150 | 164 |
|
151 |
| - return $this->response->getBody()->getContents(); |
152 |
| - } |
153 |
| - |
154 |
| - /** |
155 |
| - * @return array|mixed |
156 |
| - */ |
157 |
| - public function jsonSerialize() { |
158 |
| - return [ |
159 |
| - 'success' => $this->isSuccess(), |
160 |
| - 'expired' => $this->isSubscriptionExpired(), |
161 |
| - 'reason' => $this->reason, |
162 |
| - 'endpoint' => $this->getEndpoint(), |
163 |
| - 'payload' => $this->request->getBody()->getContents(), |
164 |
| - ]; |
165 |
| - } |
| 165 | + return $this->response->getBody()->getContents(); |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * @return array|mixed |
| 170 | + */ |
| 171 | + public function jsonSerialize() |
| 172 | + { |
| 173 | + return [ |
| 174 | + 'success' => $this->isSuccess(), |
| 175 | + 'expired' => $this->isSubscriptionExpired(), |
| 176 | + 'reason' => $this->reason, |
| 177 | + 'endpoint' => $this->getEndpoint(), |
| 178 | + 'payload' => $this->request->getBody()->getContents(), |
| 179 | + ]; |
| 180 | + } |
166 | 181 | }
|
0 commit comments