此包已被弃用,不再维护。作者建议使用bit3/github-payload包。

解析来自webhook的github API payload。

dev-develop / 1.1.x-dev 2014-11-11 11:53 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:39:16 UTC


README

版本 ![稳定构建状态](http://img.shields.io/travis/contao-community-alliance/github-payload/master.svg?style=flat-square&label=稳定构建) ![上游构建状态](http://img.shields.io/travis/contao-community-alliance/github-payload/develop.svg?style=flat-square&label=开发构建) 许可证 下载

github webhook payload

此项目包含一系列用于验证、反序列化和序列化github webhook payload的类。解析器内部使用jms/serializer,这意味着您可以按需反序列化和序列化payload。

要求

注解用于定义序列化设置。根据您的环境,您可能需要注册注解类加载器。如果您的全局自动加载器可用,则将class_exists函数注册为加载器是一种非常简单的方法。

use Doctrine\Common\Annotations\AnnotationRegistry;
AnnotationRegistry::registerLoader('class_exists');

使用示例

... 纯PHP中

<?php
require 'vendor/autoload.php';

$parser = new ContaoCommunityAlliance\GithubPayload\GithubPayloadParser();

// if you have set a secret in the webhook, set it to the parser to validate the signature
$parser->setSecret('...');

$event  = $parser->parsePhp();

... 在symfony / http-foundation中

namespace MyBundle\Controller;

class MyController
{
    public function myAction(\Symfony\Component\HttpFoundation\Request $request)
    {
        $parser = new \ContaoCommunityAlliance\GithubPayload\GithubPayloadParser();

        // if you have set a secret in the webhook, set it to the parser to validate the signature
        $parser->setSecret('...');

        $event  = $parser->parseRequest($request);
    }
}

... 在任何其他环境中

$eventName = '...'; // The event name, usually the X-Github-Event header.
$payload   = '...'; // The github payload, usually the POST body.
$signature = '...'; // The payload signature, usually the X-Hub-Signature header.

$parser = new ContaoCommunityAlliance\GithubPayload\GithubPayloadParser();

// if you have set a secret in the webhook, set it to the parser to validate the signature
$parser->setSecret('...');

$event  = $parser->parse($eventName, $payload, $signature);