Skip to content
Snippets Groups Projects
Select Git revision
  • 0570d36c1dd116e84441780ac8de03588e464093
  • main default protected
  • studip-rector
  • ci-opt
  • course-members-export-as-word
  • data-vue-app
  • pipeline-improvements
  • webpack-optimizations
  • rector
  • icon-renewal
  • http-client-and-factories
  • jsonapi-atomic-operations
  • vueify-messages
  • tic-2341
  • 135-translatable-study-areas
  • extensible-sorm-action-parameters
  • sorm-configuration-trait
  • jsonapi-mvv-routes
  • docblocks-for-magic-methods
19 results

MyRealmModel.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    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;
        }
    }