Download the PHP package earc/observer without Composer
On this page you can find all versions of the php package earc/observer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download earc/observer
More information about earc/observer
Files in earc/observer
Package observer
Short Description eArc - the explicit architecture framework - psr-14 compatible observer blueprint
License MIT
Informations about the package observer
eArc-observer
earc/observer is a ready to use and extendable psr-14 compatible observer blueprint.
Install
Bootstrap
earc/observer uses earc/di for dependency injection.
Place the above code in the section where your script/framework is bootstrapped.
Configure
earc/observer does not need any configuration.
Use
The event
Your event has to implement the EventInterface in order to be dispatchable by the dispatcher of earc/observer.
Extend the ListenerInterface if you want to be more specific.
Register Listeners
You can either use the observer object to register your listener
or use the tagging of earc/di (if the observer instance is not build yet)
Hint: Tagging does not initialize the observer nor does it autoload the observer class. Both does not autoload the listener until it is called upon to process the event.
Patience
If you pass a float
as second or third argument respectively, it is interpreted as
patience. The more patience the listener has the later it is called.
or (if the observer instance is not build yet)
Unregister Listeners
You can unregister by
or (if the observer instance is not build yet)
Note the different semantics of di_tag()
and di_clear_tags()
.
Dispatch the event
To dispatch your event use the dispatcher
It returns the event that may be modified by the listener.
advanced usage
If you want to change the behaviour of the observer you can decorate it by any
class implementing the ObserverInterface
.
Please note that every library in your project, using earc/observer, uses the
decorating class thereafter. Therefore you might be forced to write your own
dispatcher too. All you need to do is implementing the DispatcherInterface
.
releases
release 1.1
- PHP ^7.2 || ^8.0
release 1.0.3
- fix patience via tag converts float to int
- documentation completed
- test coverage 100% of documented features
release 1.0.2
- fix php does not recognise ['string' => $obj, 'method'] as callable.
release 1.0.1
- added listener interface
release 1.0
- rewrite to be psr-14 compatible
release 0.0
- initial release