1 | <?php |
||
15 | class WebhookRequestHandler |
||
16 | { |
||
17 | /** |
||
18 | * @var ServerRequestInterface |
||
19 | */ |
||
20 | private $request; |
||
21 | |||
22 | /** |
||
23 | * App secret used to verify the request sha1 |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private $secret; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $decodedBody; |
||
33 | |||
34 | /** |
||
35 | * @var Entry[] |
||
36 | */ |
||
37 | private $hydratedEntries; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $body; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $verifyToken; |
||
48 | |||
49 | /** |
||
50 | * @var EventDispatcherInterface |
||
51 | */ |
||
52 | private $dispatcher; |
||
53 | |||
54 | /** |
||
55 | * @param $secret |
||
56 | * @param $verifyToken |
||
57 | * @param EventDispatcherInterface|null $dispatcher |
||
58 | */ |
||
59 | 12 | public function __construct($secret, $verifyToken, EventDispatcherInterface $dispatcher = null) |
|
65 | |||
66 | /** |
||
67 | * @param ServerRequestInterface $request |
||
68 | */ |
||
69 | 12 | public function handleRequest(ServerRequestInterface $request) |
|
73 | |||
74 | /** |
||
75 | * Check if the token match with the given verify token. |
||
76 | * This is useful in the webhook setup process. |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 1 | public function isValidVerifyTokenRequest() |
|
94 | |||
95 | /** |
||
96 | * @return null|string |
||
97 | */ |
||
98 | 1 | public function getChallenge() |
|
104 | |||
105 | /** |
||
106 | * Check if the request is a valid webhook request |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | 3 | public function isValidCallbackRequest() |
|
123 | |||
124 | /** |
||
125 | * Check if the request is a valid webhook request |
||
126 | * |
||
127 | * @deprecated use WebhookRequestHandler::isValidCallbackRequest() instead |
||
128 | * |
||
129 | * @return bool |
||
130 | */ |
||
131 | public function isValid() |
||
135 | |||
136 | /** |
||
137 | * @return CallbackEvent[] |
||
138 | */ |
||
139 | 2 | public function getAllCallbackEvents() |
|
149 | |||
150 | /** |
||
151 | * @return Entry[] |
||
152 | */ |
||
153 | 1 | public function getEntries() |
|
157 | |||
158 | /** |
||
159 | * @return ServerRequestInterface |
||
160 | */ |
||
161 | 10 | public function getRequest() |
|
169 | |||
170 | /** |
||
171 | * @return array |
||
172 | */ |
||
173 | 5 | public function getDecodedBody() |
|
183 | |||
184 | /** |
||
185 | * Dispatch events to listeners |
||
186 | */ |
||
187 | 1 | public function dispatchCallbackEvents() |
|
203 | |||
204 | /** |
||
205 | * @param EventSubscriberInterface $subscriber |
||
206 | */ |
||
207 | 1 | public function addEventSubscriber(EventSubscriberInterface $subscriber) |
|
211 | |||
212 | /** |
||
213 | * @return Entry[] |
||
214 | */ |
||
215 | 3 | private function getHydratedEntries() |
|
232 | |||
233 | /** |
||
234 | * @return string |
||
235 | */ |
||
236 | 7 | private function getBody() |
|
246 | |||
247 | /** |
||
248 | * @return bool |
||
249 | */ |
||
250 | 3 | private function isValidHubSignature() |
|
262 | } |
||
263 |