1 | <?php |
||
11 | class Webhook |
||
12 | { |
||
13 | private static $eventSubscriptions = []; |
||
14 | private static $receivedWebhook = false; |
||
15 | |||
16 | /** |
||
17 | * Subscribe to an incoming webhook request. The callback will be invoked when a matching webhook is received. |
||
18 | * @param string $event Name of the webhook event, e.g. subscribe, unsubscribe, campaign |
||
19 | * @param callable $callback A callable function to invoke with the data from the received webhook |
||
20 | * @return void |
||
21 | */ |
||
22 | public static function subscribe($event, callable $callback) |
||
29 | |||
30 | /** |
||
31 | * Retrieve the incoming webhook request as sent. |
||
32 | * @param string $input An optional raw POST body to use instead of php://input - mainly for unit testing. |
||
33 | * @return array|false An associative array containing the details of the received webhook |
||
34 | */ |
||
35 | public static function receive($input = null) |
||
51 | |||
52 | /** |
||
53 | * Process the raw request into a PHP array and dispatch any matching subscription callbacks |
||
54 | * @param string $input The raw HTTP POST request |
||
55 | * @return array|false An associative array containing the details of the received webhook |
||
56 | */ |
||
57 | private static function processWebhook($input) |
||
70 | |||
71 | /** |
||
72 | * Call any subscribed callbacks for this event |
||
73 | * @param string $event The name of the callback event |
||
74 | * @param array $data An associative array of the webhook data |
||
75 | * @return void |
||
76 | */ |
||
77 | private static function dispatchWebhookEvent($event, $data) |
||
87 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.