2017 © Pedro Peláez
 

library event

Simple clear Event Dispatcher, compatible with Symfony Events

image

jakulov/event

Simple clear Event Dispatcher, compatible with Symfony Events

  • Saturday, January 2, 2016
  • by jakulov
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Event

Simple & clear PHP Event Dispatcher, compatible with Symfony Events, (*1)

Can be installed with composer, (*2)

composer require jakulov/event

Implements Symfony Event Interfaces, (*3)

1. Dispatcher

There's three common ways to register listeners: setConfig, addListener and use Subscriber class. Config could look like this:, (*4)

$listener1 = new \Listener\TestListener();
$listener2 = new \Listener\TestPrioritizedListener();
$config = [
    'event.test' => [  // the name of event
        [$listener1, 'onTest', 1], // listener, method and priority
        [$listener2, 'onTest'],
    ],
    'event.another_test' => [
        ['@service.listener', 'onAnotherTest'], // you can use reference to DIContainer service
    ],
];
$dispatcher = new \jakulov\Event\EventDispatcher();
$dispatcher->setConfig($config);

Link to container library: jakulov/container, (*5)

Using addListener is more usual way:, (*6)

$listener = [new \Listener\TestListener(), 'onTest'];
$dispatcher = new \jakulov\Event\EventDispatcher();
$dispatcher->addListener($event->getName(), $listener);

Also dispatcher requires a Logger instance, implementing Psr Log If don't need in logging events, just do this:, (*7)

$dispatcher = new \jakulov\Event\EventDispatcher();
$dispatcher->setLogger(new \Psr\Log\NullLogger());

2. Subscriber

Using subscriber class is usual way to setup multiple event listeners at once:, (*8)

$dispatcher = new \jakulov\Event\EventDispatcher();
$dispatcher->addSubscriber(new \Listener\TestSubscriber());

3. Event

Class \jakulov\Event\AbstractEvent should be parent for all event objects used with dispatcher. You can dispatch events without event object, but objects is the right way to pass event data to listeners., (*9)

Tests

Run: ./run_tests.sh, (*10)

Tests are also examples for usage library, (*11)

The Versions

02/01 2016

dev-master

9999999-dev

Simple clear Event Dispatcher, compatible with Symfony Events

  Sources   Download

MIT

The Requires

 

The Development Requires