Download the PHP package superbalist/php-event-pubsub without Composer
On this page you can find all versions of the php package superbalist/php-event-pubsub. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download superbalist/php-event-pubsub
More information about superbalist/php-event-pubsub
Files in superbalist/php-event-pubsub
Package php-event-pubsub
Short Description An event protocol and implementation over pub/sub
License MIT
Informations about the package php-event-pubsub
php-event-pubsub
An event protocol and implementation over pub/sub
This library builds on top of the php-pubsub package and adds support for listening to and dispatching events over pub/sub channels.
Installation
Integrations
Want to get started quickly? Check out some of these integrations:
Usage
Simple Events
A SimpleEvent
is an event which takes a name and optional attributes.
Topic Events
A TopicEvent
is an event which takes a topic, name, version and optional attributes.
Schema Events
A SchemaEvent
is an extension of the TopicEvent
and takes a schema and optional attributes. The topic, name and
version are derived from the schema.
The schema must be in the format (protocol)://(......)?/events/(topic)/(channel)/(version).json
Custom Events
You can easily use a custom event structure by writing a class which implements the EventInterface
interface.
You will then need to write a custom translator to translate incoming messages to your own event object.
Your event must implement the following methods.
Translators
A translator is used to translate an incoming message into an event.
The package comes bundled with a SimpleEventMessageTranslator
, TopicEventMessageTranslator
and a
SchemaEventMessageTranslator
.
Custom Translators
You can easily write your own translator by implementing the MessageTranslatorInterface
interface.
Your translator must implement the following methods.
Validators
A validator is an optional component used to validate an event upon dispatch.
JSONSchemaEventValidator
This package comes bundled with a JSONSchemaEventValidator
which works with SchemaEvent
type events.
This validator validates events against a JSON Schema Spec using the JSON Guard PHP package.
Please see the "Schema Events" section above and the JSON Guard documentation for usage examples.
Custom Validators
You can write your own validator by implementing the EventValidatorInterface
interface.
Your validator must implement the following methods.
Attribute Injectors
An attribute injector allows you to have attributes automatically injected into events when events are dispatched.
The library comes bundled with a few injectors out of the box.
- DateAttributeInjector - injects a
date
key with an ISO 8601 date time - GenericAttributeInjector - injects a custom
key
andvalue
- HostnameAttributeInjector - injects a
hostname
key with the server hostname - Uuid4AttributeInjector - injects a
uuid
key with a UUID-4
You can write your own injector by implementing the AttributeInjectorInterface
or by passing a callable (which returns
an array with a 'key' and 'value') to the event manager.
Your injector must implement the following methods.
Here's a usage example demonstrating both a class and a callable.
Custom Class
Callable
Error Handling
The library supports error handlers for when event translation fails, listen expression fails and validation fails.
You can pass callables into the EventManager constructor, or set them as follows:
Examples
The library comes with Dockerfile for running the example scripts.
Run make up
.
You will start at a bash
prompt in the /opt/php-event-pubsub
directory.
To run the examples:
All versions of php-event-pubsub with dependencies
superbalist/php-pubsub Version ^2.0
composer/semver Version ^1.4
league/json-guard Version ^0.5.1
ramsey/uuid Version ^3.5