bazo/nette-events-extension

Really simple events dispatcher for Nette Framework

dev-master 2017-02-06 20:12 UTC

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);