Download the PHP package designs2/event-dispatcher without Composer
On this page you can find all versions of the php package designs2/event-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download designs2/event-dispatcher
More information about designs2/event-dispatcher
Files in designs2/event-dispatcher
Package event-dispatcher
Short Description Event dispatcher service for Contao Open Source CMS
License LGPL-3.0+
Homepage http://c-c-a.org/
Informations about the package event-dispatcher
![Stable Build Status](http://img.shields.io/travis/contao-community-alliance/event-dispatcher/master.svg?style=flat-square&label=stable build) ![Upstream Build Status](http://img.shields.io/travis/contao-community-alliance/event-dispatcher/develop.svg?style=flat-square&label=dev build)
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.
But events are more elastic than hooks. They can be hand round, consumed, stopped or bubble upon a hierarchy.
The real big reasons, why an event dispatcher exists for Contao are:
- Events are standard paradigm in software design.
- Hooking is a paradigm to alter the behavior of a software, is it not designed for notifications.
- Hooks are only a special form of events.
- The symfony event dispatcher this extension based on is widely used.
- 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.
First and mostly used is an event listener. It is designed to listen on a single event.
Second the event subscriber is designed to listen on multiple events.
Event listener per configuration
Since version 1.3 there are two ways to define your listeners per configuration.
/config/event_listeners.php
We recommend to use this method!
The file /config/event_listeners.php
must return an array of event names as keys and listeners as values.
/config/config.php
In your /config/config.php
use $GLOBALS['TL_EVENTS']
to register your event handlers.
With a closure:
With a static callable:
With an object callable:
Handle with priority
To define the priority, you can use an array with the listener as first and the priority as second element.
Event listener per code
Event subscriber per configuration
Since version 1.3 there are two ways to define your listeners per configuration.
/config/event_subscribers.php
We recommend to use this method!
The file /config/event_subscribers.php
must return an array of subscribers.
/config/config.php
In your /config/config.php
use $GLOBALS['TL_EVENT_SUBSCRIBERS']
to register your subscribers.
With a factory:
With an object class name:
With an object instance:
Event subscriber per code
All versions of event-dispatcher with dependencies
contao/core Version >=2.11,<4-dev
contao-community-alliance/composer-plugin Version ~2.0
contao-community-alliance/dependency-container Version ~1.6
symfony/event-dispatcher Version ~2.3