bazo / nette-events-extension
Really simple events dispatcher for Nette Framework
Installs: 7 928
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.5.0
- nette/di: *
This package is not auto-updated.
Last update: 2024-10-26 17:56:04 UTC
README
Really simple events dispatcher for Nette Framework.
Usage:
add this to your config.neon
extensions:
- Bazo\Events\DI\EventsExtension
services:
- {class: Listener1, tags: [subscriber]}
- {class: Listener2, tags: [subscriber]}
...
A subscriber must implement getSubscribedEvents static function from Bazo\Events\Subscriber interface
class Listener1 implements Bazo\Events\Subscriber { public static function getSubscribedEvents() { return [ 'event1' => [ 'callback1', 'callback2', ], 'event2' => [ 'callback3', 'callback4', ] ]; } public function callback1($arg1, $arg2, ...) {...} }
Callbacks are function names.
Then you dispatch an event like this:
$args = [ $arg1, $arg2 ]; $dispatcher->dispatchEvent('event1', $args);