shancept / event
Events
v1.0.2
2022-11-28 11:55 UTC
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- dg/bypass-finals: ^1.3
- friendsofphp/php-cs-fixer: ^3.13
- phpunit/phpunit: ^9
- psr/container: ^1.1.1
- vimeo/psalm: ^4.29
README
Events allow you to insert custom code into existing code at specific points in execution. You can attach custom code to an event so that when the event fires, the code is automatically executed.
install:
composer require shancept/event
Usage:
first case
- create event class implements EventInterface. Example.
- create event handler class. Example.
- call trigger event at the right place
Event::trigger(new Event())
. - subscribe to the event before executing it
Event::listen(SomeClass::class, static function ($event) {})
.
second case
- use trait in your class.
- record all events via
EventTrait::recordEvent
. - call in the right place:
EventBus::dispatch()
. - pass
EventTrait::releaseEvents
result to the "dispatch" function parameter.