Download the PHP package nimbly/announce without Composer
On this page you can find all versions of the php package nimbly/announce. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nimbly/announce
More information about nimbly/announce
Files in nimbly/announce
Package announce
Short Description PSR-14 event dispatcher with subscriber support.
License MIT
Informations about the package announce
Announce
A simple framework agnostic PSR-14 event dispatcher for your event-driven application.
Features
- Uses PHP's
#Attribute
feature to register class methods as event handlers - Optional PSR-11 Container support
- Full autowiring support for your subscribers and listeners - pass in not just the event but any needed services or other dependencies!
Installation
Quick start
Create an event class
Your events can be standalone classes or they can extend the StoppableEvent
abstract class. By extending the StoppableEvent
abstract you gain the ability to stop event propogation if needed.
Create a subscriber
Subscribers are classes that will handle your events. You can have as many subscribers as you would like.
To register a subscriber's method to handle a particular event or set of events, use the Nimbly\Announce\Subscribe
attribute and pass in a comma separated list of event names to listen for.
Initiate Dispatcher
To register your subscriber's with the event dispatcher, pass in an array of class names or instances into the Dispatcher
constructor.
You can also pass in a PSR-11 compliant container instance to be used in autowiring your subscribers as well as for event handlers on your subscribers.
Dispatch event
To trigger an event, just call the dispatch
method with the event instance.
Stopping event propagation
If you need to stop event propagation during its lifetime, just call the stop()
method on the event instance. The event will no longer be propagated to any further subscribed listeners. This requires the event to extend from the StoppableEvent
abstract.
Registering individual listeners
Alternatively, you can register individual events using the listen
method.
Wildcard listeners
You can register a "wild card" listener by using the *
event name. This will subscribe to all events fired.