Github Webhook
, (*1)
Requirements
- PHP 5.3+
- symfony/http-foundation >= 2.3
- symfony/event-dispatcher >= 2.3
Installation
Composer
You need first to download this library using composer
., (*2)
composer require smalot/github-webhook
Go to GetComposer.org to install Composer on your environment., (*3)
Example
From scratch
<?php
require_once 'vendor/autoload.php';
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
// Todo: add listener to event dispatcher.
$listener = ...
$dispatcher->addListener(\Smalot\Github\Webhook\Events::WEBHOOK_REQUEST, $listener);
$webhook = new \Smalot\Github\Webhook\Webhook($dispatcher);
$event = $webhook->parseRequest($request, 'password');
Using Symfony in controller
<?php
namespace AppBundle\Controller;
use Smalot\Github\Webhook\Webhook;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class GithubController extends Controller
{
public function webhookAction(Request $request)
{
$dispatcher = $this->get('event_dispatcher');
$webhook = new Webhook($dispatcher);
$event = $webhook->parseRequest($request, 'password');
return Response('ok');
}
}
Don't forget to previously to register any event listener., (*4)