Download the PHP package turanct/webhooks without Composer
On this page you can find all versions of the php package turanct/webhooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download turanct/webhooks
More information about turanct/webhooks
Files in turanct/webhooks
Package webhooks
Short Description Trigger WebHooks from your project
License MIT
Homepage http://github.com/turanct/webhooks
Informations about the package webhooks
WebHooks
Goal
Create a very simple and easy to use library that triggers webhooks.
Basic Usage
The main interface that this package provides is the WebHooks
interface. It provides a single method send()
which takes a WebHook
instance and sends it. You can then configure your Dependency Injection Container or Service Locator to build the specific implementation of that interface, depending on your needs. Let's see how you'd use this in a dummy controller:
Now, every time we visit the url /send-webhook
on our application, a webhook will be triggered to https://example.com/webhooks
with the payload we specified above. When something goes wrong, a WebHookWasNotSent
exception will be thrown, which we can catch
, as seen in the example above.
Which implementation to use?
At the time of writing, the recommended implementation of the WebHooks
interface is the WebHooksGeneric
class. You can instantiate it like this in your Dependency Injection Container:
Now the webhooks service is registered as such in the Dependency Injection container (Pimple in the example).
Why the HttpClient
interface and how to use it?
We chose not to ship a default HTTP client implementation with this package to be able to use it with all existing HTTP client packages. We just provided a very small interface that you can easily implement for the HTTP client of your choice. You could then package that implementation in a separate package, and put this package in the composer require statements of your package. That way, dependencies resolve in the right direction (concrete depends on abstract).
Your implementation of the interface should make sure that
- it has an
execute()
method which takes aHttpRequest
and returns aHttpResponse
- it catches all exceptions from the underlying Http client and wraps them in a
HttpClientException
if something fails that we can't recover from.
What about Retries & Async implementations?
They are in the making. Issues have been created in this repo for that.