psp-biz/event-service

A framework-agnostic event service library.

dev-main 2023-11-20 11:21 UTC

This package is not auto-updated.

Last update: 2024-05-06 12:34:39 UTC


README

This Event Service Library provides a simple interface for PHP applications to dispatch events to a specified endpoint. It is designed to be framework-agnostic and can be used with any PHP project that uses Composer for dependency management.

Features

  • Framework-agnostic implementation.
  • Supports PSR-4 autoloading.
  • Implements PSR-7 HTTP message interfaces and PSR-18 HTTP Client for communication.
  • Utilizes Monolog for logging event dispatching processes.
  • Configurable to handle different endpoints and authentication methods.
  • Provides an easy-to-use API for dispatching events.

Installation

Use Composer to install the Event Producer Library into your project:

composer require psp-biz/event-service

Usage

To use the Event Producer, you need to require the Composer autoload file and instantiate the EventProducer class. Then, dispatch events using the dispatchEvent method:

require_once __DIR__ . '/vendor/autoload.php';

use YourVendor\EventProducer\EventProducer;

// Initialize the Event Producer
$eventProducer = new EventProducer();

// Dispatch an event
$eventProducer->dispatchEvent('event.name', [
    // Event data array
]);

The dispatchEvent method takes two parameters:

  1. eventName (string): The name of the event you want to dispatch.
  2. eventData (array): An associative array containing the data for the event.

Configuration

By default, the library is configured to log to logs/events.log and send events to a predefined endpoint. To customize these settings, you can modify the constructor of the EventService class or expose configuration methods as needed.

Logging

The library uses Monolog for logging. Logs are written to logs/events.log. You can change the log settings by editing the EventService class constructor.

Dependencies

The library depends on the following packages:

  • guzzlehttp/guzzle: For sending HTTP requests.
  • http-interop/http-factory-guzzle: PSR-17 HTTP Factory implementation for Guzzle.
  • monolog/monolog: For logging events and errors.

Contributing

No need, thanks though.

License

The Event Service Library is open-sourced software licensed under the MIT license.