Select Git revision
Forked from
Stud.IP / Stud.IP
Source project has a limited visibility.
-
Jan-Hendrik Willms authoredJan-Hendrik Willms authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
EventController.php 1.23 KiB
<?php
namespace TracToGitlab;
abstract class EventController extends Controller
{
private $payload = null;
protected function verifySecret(string $secret): bool
{
return $_SERVER['HTTP_X_GITLAB_TOKEN'] === $secret;
}
protected function verifyEventType(string $type): bool
{
return $_SERVER['HTTP_X_GITLAB_EVENT'] === $type;
}
protected function getFromPayload(...$keys)
{
if ($this->payload === null) {
$this->payload = $this->getPayloadFromRequest() ?? false;
}
if ($this->payload === false) {
throw new \Exception('No payload detected');
}
$result = $this->payload;
foreach ($keys as $key) {
if (!isset($result[$key])) {
throw new \Exception("Invalid payload key {$key}");
}
$result = $result[$key];
}
return $result;
}
private function getPayloadFromRequest(): ?array
{
$input =file_get_contents('php://input');
if (!$input) {
return null;
}
$payload = json_decode($input, true);
if (!$payload || !is_array($payload)) {
return null;
}
return $payload;
}
}