Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

walmsles/silverstripe-event-dispatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

silverstripe-event-dispatch

Silverstripe integration of walmsles/event-dispatch PHP module.

Maintainer Contact

Requirements

  • Silverstripe 3.3 (earlier versions probably OK but not tested)

Installation

composer install walmsles/silverstripe-event-dispatch

Documentation

A nice decoupled event dispatch model integrated into Silverstripe using a publish/subscribe mechanism.

Event Module allows registration of listeners to arbitrary events which can be fired anywhere and at anytime. Listeners are any valid callable PHP structure as defined by PHP's call_user_func_array. e.g. Closure, function name, array definining Class instance and method (array($this, 'myMethod'))

Calling Methods

There are two ways to call functions on the event dispatcher that have identical results

  • EventDispatcher::dispatch('myEvent', array('event data', 'event data 2'));
  • EventDispatcher::inst()->dispatch('myEvent', array('event data', 'event data 2'));

While the first method is more concise as it uses __callStatic to forward the calls the second method will allow your IDE to autocomplete the available methods. The choice is yours.

EventDispatcher::inst()->subscribe('myEvent', function($myData1, $myData2) {
    // so somehting with $myData
    
    return $myData1 . ' ' . $myData2;
});

/** @var array $responses */
$responses = EventDispatcher::inst()->dispatch('myEvent', array('event data', 'event data 2'));

Full documentation is available here

About

Packaging of walmsles/event-dispatch into Silverstripe CMS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages