|Last Updated|| ||Ratings|| ||Unique User Downloads|| ||Download Rankings|
|2017-06-01 (2 years ago) || 58%||Total: 75 ||All time: 9,449 This week: 481|
This class implements a immutable event.
It can store the details of an event using the constructor like the name of the event, date and time it was created, source object, and subject details.
Once created, the details of the event cannot be changed.
|Event handling is a form of integration different programming components by registering one object to handle events that occur in the other message.
Events objects just contain details of what happened in the source object but once they are emitted, the event data should not be changed.
This package implements an event system on which the actual event object is immutable because once it is created, it cannot be changed.
PHP Event Component
This free as in freedom project aims to deliver a generic, clean and immutable php event component.
The build status of the current master branch is tracked by Travis CI:
The scrutinizer status are:
Minimum PHP version is:
Take a look on openhub.net.
mkdir -p vendor/net_bazzline/php_component_event
git clone https://github.com/bazzline/php_component_event .
composer require net_bazzline/php_component_event:dev-master
- zero dependencies
- immutable object
* no propagation support out of the box
* no intended support for changing the subject
- event contains
* occurred at
* subject - the event arguments or data (array|Collection)
| Name | Description |
| --- | --- |
| occurred at | when did the event happen |
| name | the unique identifier for this event (I prefer human readable names instead of numbers as long as possible and I want to encourage you to do the same) |
| source | a unique identifier to track down the source where the event was created |
| subject | the event arguments or data, an array or an object like a collection |
- whenever you are dealing with events, it is getting complicated quickly since your event is doing to much or carrying to much responsibility
- you can use
$event instanceof MyEvent to listen only to a specific event
- instead of adding the option to stop the propagation, I would like to encourage you to follow a different way
* create a generic event which fires your real event only under special circumstances (to move the propagation logic into an event)
* create and fire an event which rejects your previous changes
- because of the not implemented support for stopping the propagation, we do not need priorities while dispatching (less complexity :-))
- extend from
GenericEvent to add your type hint for the phpdoc block of the
public method source()
- use or extend the
GenericEventBuilder to set your well defined event name, sources etc.
Using an event is one of the best indicator that your information has to leave the current domain boundraies.
Keep the event simple, the structure of data should be the contract you as emitter and the event listener have agreed on.
source - @todo
I treat an event like a taken statement.
Once articulated, you can not change it since it is emitited and transported by your preferred transmission medium to the receiver.
All you can do is to add explenations or improvments to your statement.
Worst but possible, if you figure out you where wrong, your only chance is to withdraw your statement.
But everything you emit (or say) is another statement (or event).
source - @todo
[...] I characterize the data on a Domain Event as immutable source data that captures what the event is about and mutable processing data that records what the system does in response to it. [...]
API is available at bazzline.net.
* updated some wording here and there
- 0.0.3 - released at 2017-01-28
* updated minimum requirements to php 5.6
- 0.0.2 - released at 29.08.2016
* added type hint
DateTime in class
- 0.0.1 - released at 21.08.2016
Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if use it. Make a donation if you love it :-].
||Applications that use this package
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.