Added an example code

This commit is contained in:
Cédric Belin
2018-11-02 00:03:45 +01:00
parent 3891e435c1
commit 3ffe5d6b9c
6 changed files with 27 additions and 58 deletions

18
example/main.php Normal file
View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
use Gitea\{PushEvent};
/**
* Handles the payload of a Gitea push event.
* @return PushEvent The parsed payload.
* @throws UnexpectedValueException The request headers or the request body are invalid.
*/
function main(): PushEvent {
if (!isset($_SERVER['HTTP_X_GITEA_DELIVERY']) || !isset($_SERVER['HTTP_X_GITEA_EVENT']))
throw new UnexpectedValueException('Invalid payload data.');
$data = json_decode((string) file_get_contents('php://input'));
if (!is_object($data)) throw new UnexpectedValueException('Invalid payload data.');
return PushEvent::fromJson($data);
}