smalot / github-webhook
处理 webhook 回调的 Github API。
v0.2
2015-12-28 15:04 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- symfony/event-dispatcher: >=2.3
- symfony/http-foundation: >=2.3
This package is not auto-updated.
Last update: 2024-09-11 23:56:12 UTC
README
要求
- PHP 5.3+
- symfony/http-foundation >= 2.3
- symfony/event-dispatcher >= 2.3
安装
Composer
您首先需要使用 composer
下载此库。
composer require smalot/github-webhook
前往 GetComposer.org 在您的环境中安装 Composer。
示例
从头开始
<?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');
在控制器中使用 Symfony
<?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'); } }
别忘了之前注册任何事件监听器。