2017 © Pedro Peláez
 

contao-module contao-event-dispatcher

Event dispatcher service for Contao Open Source CMS

image

bit3/contao-event-dispatcher

Event dispatcher service for Contao Open Source CMS

  • Wednesday, October 30, 2013
  • by tril
  • Repository
  • 0 Watchers
  • 0 Stars
  • 324 Installations
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Event dispatcher for Contao Open Source CMS

Why an event dispatcher for Contao Open Source CMS, are the hooks not enough? First you need to understand, there is no real difference between hooks and events. The are both notifications from within the system., (*1)

But events are more elastic than hooks. They can be hand round, consumed, stopped or bubble upon a hierarchy., (*2)

The real big reasons, why an event dispatcher exists for Contao are:, (*3)

  1. Events are standard paradigm in software design.
  2. Hooking is a paradigm to alter the behavior of a software, is it not designed for notifications.
  3. Hooks are only a special form of events.
  4. The symfony event dispatcher this extension based on is widely used.
  5. The event dispatcher can handle every form of callbacks, like closures or static methods.

Listen on events

The event dispatcher provide two ways to listen on events., (*4)

First and mostly used is an event listener. It is designed to listen on a single event., (*5)

Second the event subscriber is designed to listen on multiple events., (*6)

Event listener per configuration

Use $GLOBALS['TL_EVENTS'] to register your event handlers., (*7)

With a closure:, (*8)

$GLOBALS['TL_EVENTS']['event-name'][] = function($event) {
    // event code
};

With a static callable:, (*9)

$GLOBALS['TL_EVENTS']['event-name'][] = array('MyClass', 'myCallable');

With an object callable:, (*10)

$GLOBALS['TL_EVENTS']['event-name'][] = array(new MyClass(), 'myCallable');

Handle with priority

To define the priority, you can use an array with the listener as first and the priority as second element., (*11)

$GLOBALS['TL_EVENTS']['event-name'][] = array($listener, $priority);

Event listener per code

$container['event-dispatcher']->addListener('event-name', $listener);

Event subscriber per configuration

Use $GLOBALS['TL_EVENT_SUBSCRIBERS'] to register your subscribers., (*12)

With a factory:, (*13)

$GLOBALS['TL_EVENT_SUBSCRIBERS'][] = function($eventDispatcher) {
    return new MyEventSubscriber();
};

With an object class name:, (*14)

$GLOBALS['TL_EVENT_SUBSCRIBERS'][] = 'MyEventSubscriber';

With an object instance:, (*15)

$GLOBALS['TL_EVENT_SUBSCRIBERS'][] = new MyEventSubscriber();

Event subscriber per code

$container['event-dispatcher']->addSubscriber(new MyEventSubscriber());

The Versions

30/10 2013

dev-master

9999999-dev

Event dispatcher service for Contao Open Source CMS

  Sources   Download

LGPL-3.0+

The Requires

 

event contao