1. Go to this page and download the library: Download designs2/event-dispatcher library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
designs2 / event-dispatcher example snippets
return array(
// With a closure
'event-name' => array(
function($event) {
// event code
}
),
// With a static callable
'event-name' => array(
array('MyEventListener', 'myCallable')
),
// With an object callable
'event-name' => array(
array(new MyEventListener(), 'myCallable')
),
// With a service object
'event-name' => array(
array($GLOBALS['container']['my_event_listener'], 'myCallable')
),
// You can wrap the listener into an array with a priority
'event-name' => array(
array($listener, $priority)
),
);
return array(
// With a factory
function($eventDispatcher) {
return new MyEventSubscriber();
},
// With an object class name
'MyEventSubscriber',
// With an object instance
new MyEventSubscriber(),
// With a service object
$GLOBALS['container']['my_event_subscriber'],
);
$GLOBALS['TL_EVENT_SUBSCRIBERS'][] = function($eventDispatcher) {
return new MyEventSubscriber();
};