-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
29 lines (22 loc) · 894 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
require_once __DIR__ . '/vendor/autoload.php';
use tei187\GitDisWebhook\Factories\MessageFactory;
use tei187\GitDisWebhook\Factories\PayloadFactory;
use tei187\GitDisWebhook\Factories\WebhookFactory;
// define root path
define('GHDWEBHOOK_ROOT', __DIR__ . '/');
// assign factories
$messageFactory = new MessageFactory();
$payloadFactory = new PayloadFactory();
$webhookFactory = new WebhookFactory();
// get the GitHub event and payload
$data = file_get_contents('php://input');
$event = $_SERVER['HTTP_X_GITHUB_EVENT'] ?? null;
// create the appropriate payload, webhook and message profiles
$payload = $payloadFactory->createPayload($event, $data);
$webhook = $webhookFactory->createWebhook($payload);
$message = $messageFactory->createMessage($event, $webhook);
// if all factories produced objects, send message
if ($payload && $webhook && $message) {
$message->send();
}