mc-cms-namelessmc/modules/Core/hooks/WebHook.php
Sam 6009c81aff
fix: validate webhook urls via create webhooks endpoint (#3736)
Co-authored-by: Sam <samerton@users.noreply.github.com>
2026-06-27 13:09:43 +01:00

35 lines
867 B
PHP

<?php
/**
* Webhook handler class
*
* @package NamelessMC\Events
* @author Partydragen
* @version 2.3.0
* @license MIT
*/
class WebHook implements WebhookDispatcher {
public static function execute(AbstractEvent $event, string $webhook_url): void {
if (!$event instanceof HasWebhookParams) {
return;
}
$params = $event->webhookParams();
if (!isset($params['event'])) {
$params['event'] = $event::name();
}
$json = json_encode($params, JSON_UNESCAPED_SLASHES);
$httpClient = HttpClient::post($webhook_url, $json, [
'headers' => [
'Content-Type' => 'application/json',
],
'allow_redirects' => false,
]);
if ($httpClient->hasError()) {
trigger_error($httpClient->getError());
}
}
}