PHP code example of gnello / webhook-manager

1. Go to this page and download the library: Download gnello/webhook-manager 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/ */

    

gnello / webhook-manager example snippets




use \Gnello\WebhookManager\App;
use \Gnello\WebhookManager\Services\BitbucketService;

$webhookManager = new App();

//Action on build passed
$webhookManager->add([BitbucketService::BUILD_STATUS_CREATED, BitbucketService::BUILD_STATUS_UPDATED], function(BitbucketService $service) {
    $payload = $service->getPayload();

    if ($payload['commit_status']['state'] == 'SUCCESSFUL') {
        //do some stuff
    }
});

$webhookManager->listen();



use \Gnello\WebhookManager\App;
use \Gnello\WebhookManager\Services\GithubService;

$webhookManager = new App(['service' => GithubService::class]);

//Action on push event
$webhookManager->add(GithubService::PUSH, function(GithubService $service) {
    $payload = $service->getPayload();

    //do some stuff
});

$webhookManager->listen();



use \Gnello\WebhookManager\App;
use \Gnello\WebhookManager\Services\TravisCIService;

$webhookManager = new App(['service' => TravisCIService::class]);

//Action on build passed
$webhookManager->add(TravisCIService::PUSH, function(TravisCIService $service) {
    $payload = $service->getPayload();

    if ($payload['state'] === 'passed') {
        //do some stuff
    }
});

$webhookManager->listen();



use \Gnello\WebhookManager\App;

$webhookManager = new App(['service' => \YourCustomService::class]);

//Action on custom event
$webhookManager->add('custom_event', function(\YourCustomService $service) {
    $payload = $service->getPayload();
    //do some stuff
});

$webhookManager->add('another_event', function(\YourCustomService $service) {
    //do some stuff
});

$webhookManager->listen();

//github
$webhookManager = new \Gnello\WebhookManager\App([
    'service' => \Gnello\WebhookManager\Services\GithubService::class
]);

//travis ci
$webhookManager = new \Gnello\WebhookManager\App([
    'service' => \Gnello\WebhookManager\Services\TravisCIService::class
]);

//custom service
$webhookManager = new \Gnello\WebhookManager\App([
    'service' => \Gnello\WebhookManager\Services\YourCustomService::class
]);

$webhookManager = new \Gnello\WebhookManager\App([
    'json_decode_assoc' => false
]);