PHP code example of fatindeed / gitlab-webhook-handler

1. Go to this page and download the library: Download fatindeed/gitlab-webhook-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fatindeed / gitlab-webhook-handler example snippets


    use TimoReymann\GitlabWebhookLibrary\Core\Webhook;
    use TimoReymann\GitlabWebhookLibrary\Token\SecretToken;

    $hook = new Webhook(new SecretToken('mySuperSecretToken'));
    $event = $hook->parse();
    

    use TimoReymann\GitlabWebhookLibrary\Event\EventType;

    $eventType = new EventType;
    $event = $eventType->getEventDataFromBody(file_get_contents('php://input'));
    

use Fatindeed\GitlabWebhookHandler\EventSubject;

$object = new YourWebhookHandler; // Replace with you webhook handler

$subject = new EventSubject;
$subject->attach($object);
$subject->dispatch($event); // Event created above

    use Enqueue\Fs\FsConnectionFactory;
    use Fatindeed\GitlabWebhookHandler\EventSubject;

    $context = (new FsConnectionFactory)->createContext(); // Create a filesystem queue

    $subject = new EventSubject;
    $subject->dispatch($event, $context); // Event created above
    

    use Enqueue\Fs\FsConnectionFactory;
    use Fatindeed\GitlabWebhookHandler\EventSubject;

    $object = new YourWebhookHandler; // Replace with you webhook handler
    $context = (new FsConnectionFactory)->createContext(); // Create a filesystem queue

    $subject = new EventSubject;
    $subject->signalInstall(SIGTERM, [$subject, 'terminate']); // Alternative
    $subject->attach($object);
    $subject->run($context);
    

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('application');
$logger->pushHandler(new StreamHandler(STDOUT, Logger::INFO));
$subject = new EventSubject($logger);
# code...