Download the PHP package widop/github-hook-provider without Composer
On this page you can find all versions of the php package widop/github-hook-provider. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package github-hook-provider
README
The library provides a Silex provider allowing you to execute your job on any Github WebHook.
Installation
The library is distributed through Composer. So, fist, install it :)
Create a composer.json
file at the root directory of you project & put the following inside:
As the library provides optional debugging, you can enable it by installing & registering the build-in Silex MonologServiceProvider:
Then, install the libraries:
Create your application
Now, we have everything locally, we can create the Silex application. Usually, we follow the following structure:
The web/hook.php
looks like:
In this structure, the web
directory is the vhost root directory of our application & the hook.php
script is the
frontend controller managing our Github WebHook. So, if we create a vhost with my-domain.com
as domain, we can put
http://my-domain.com/hook.php
as Github Webhook.
The src
directory should not exist yet. You can create it, we will need it in the next steps :)
Register the provider
The Silex application (which do nothing...) is up :)
Now, we need to register & configure the Wid'op Github Hook provider which will allow us to play with Github hooks. For
that, simply update the hook.php
:
When you go to the Github WebHook configuration accessible in your Github repo setting, you have a list of IPs which can be trusted for Github WebHooks. The provider needs this list of IPs in order to secure the entry point. You can obviously provide an empty array but it is strongly not recommended!
Mount the controller
The Silex application with his provider is now well configured (but still do nothing...) :)
To finish the work, we need to mount the controller. One more time, update the hook.php
:
You're done! The set up is finished.
What next?
Next? It can be interesting to write our custom stuffs which will be executed when a valid hook is received... :)
How does it work?
As Silex itself, the provider is builded around the event dispatcher. When a hook is received & has been validated
against the IP firewall & the hook configuration, the github_hook
event is fired & an event wrapping all informations
about the hook are propagated to all listeners/subscribers. So, we just have to write our event listener/subscriber.
You can register as many listener/subscribers you want & archive more complex use cases by playing with priorities or event propagation...
Write the Hook Subscriber
We recommend you to put your code, in the src
directory:
As we have added the Acme
namespace, we need update the composer.json
in order to autoload new classes:
Register the Hook Subscriber
Our hook subscriber is defined & it does our custom stuffs. Now, we need to register it on the event dispatcher. For
that, we have two solutions: Directly in the hook.php
or through a Silex provider.
Direct
Register our hook subscriber in the hook.php
:
Silex Provider
Create our hook provider:
Then, register our hook provider in the hook.php
:
Contribute
We love contributors! The library is open source, if you'd like to contribute, feel free to propose a PR!
License
The Wid'op Github Hook Silex Provider is under the MIT license. For the full copyright and license information, please read the LICENSE file that was distributed with this source code.