/webhooks

A agnostic package for publishing internal events externally via webhooks

Primary LanguagePHPMIT LicenseMIT

Webhooks

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

An agnostic package that handles the registration and delivery of webhook notifications to external systems

Install

Via Composer

$ composer require benrowe/webhooks

Usage

<?php

$webhookService = new \Benrowe\Webhooks\WebhookService();
$webhook = new \Benrowe\Webhooks\Webhook('http://localhost/path/to/call');
$webhook->listenTo(MyEvent::class);
$webhookService->subscribe($webhook);

// later
$webhookService->dispatchEvent(new MyEvent, $payload);

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email ben.rowe.83@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Notes

Service Interface

// constructor
$service = new \Benrowe\Webhooks\WebhookService(StorageInterface $storage);

// primary methods
$service->subscribe(WebhookSubscription $subscription);
$service->unsubscribe(WebhookSubscription $subscription);
$service->dispatchEvent(WebhookEvent $event);
$service->dispatch(string $eventName);

// secondary methods
$service->protocols;//collection
$service->protocols->register(ProtocolHandlerInterface $handler);

Structures

Event {
  Name string
}

WebhookSubscription {
  PayloadUrl string
  Conte
}

Ideas

  • Persistance of the registered webhooks is handled by the StorageInterface
  • Protocol handlers are registered against the service (http(s), amqp). Each protocol handler
  • Content type handlers are registered against the service (json, yaml, xml, etc). When registering a new Subscription, it will verify the payload url to see if there's an appropriate handler registered.
    • By default we will include a http(s) handler