PHP code example of swop / github-webhook-middleware
1. Go to this page and download the library: Download swop/github-webhook-middleware 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/ */
swop / github-webhook-middleware example snippets
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Swop\GitHubWebHook\Security\SignatureValidator;
use Swop\GitHubWebHookMiddleware\GithubWebHook;
$request = \Zend\Diactoros\ServerRequestFactory::fromGlobals();
$middleware = new GithubWebHook(new SignatureValidator(), 'my_secret');
$next = function (RequestInterface $request, ResponseInterface $response) {
// The security has been check.
// Do some stuff with the web hook...
return new \Zend\Diactoros\Response\JsonResponse(['status' => 'ok']);
};
$server = \Zend\Diactoros\Server::createServerFromRequest($middleware, $request);
$server->listen($next);
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Zend\Stratigility\MiddlewarePipe;
use Zend\Stratigility\NoopFinalHandler;
use Zend\Diactoros\Server;
use Zend\Diactoros\Response\JsonResponse;
use Swop\GitHubWebHook\Security\SignatureValidator;
use Swop\GitHubWebHookMiddleware\GithubWebHook;
$app = (new MiddlewarePipe())
->pipe(new GithubWebHook(new SignatureValidator(), 'my_secret'))
->pipe('/', function (RequestInterface $request, ResponseInterface $response) {
// The security has been check.
// Do some stuff with the web hook...
return new JsonResponse(['status' => 'OK']);
});
$request = \Zend\Diactoros\ServerRequestFactory::fromGlobals();
Server::createServerFromRequest($app, $request)
->listen(new NoopFinalHandler())
;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.