2017 © Pedro Peláez
 

library event-dispatcher

A minimalistic interface to relay generic events to registered listeners

image

onoi/event-dispatcher

A minimalistic interface to relay generic events to registered listeners

  • Saturday, January 27, 2018
  • by mwjames
  • Repository
  • 1 Watchers
  • 1 Stars
  • 127,855 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

Event dispatcher

Build Status Code Coverage Scrutinizer Code Quality Latest Stable Version Packagist download count, (*1)

A minimalistic event dispatcher (observer) interface that was part of the Semantic MediaWiki code base and is now being deployed as independent library., (*2)

Requirements

PHP 5.3/HHVM 3.3 or later, (*3)

Installation

The recommended installation method for this library is by either adding the dependency to your composer.json., (*4)

{
    "require": {
        "onoi/event-dispatcher": "~1.0"
    }
}

Usage

class BarListener implements EventListener {

    public function execute( DispatchContext $dispatchContext = null ) {
        // Do something
    }

    public function isPropagationStopped() {
        return false;
    }
}

```php class ListenerCollectionRegistry implements EventListenerCollection {, (*5)

private $eventListenerCollection;

public function __construct( EventListenerCollection $eventListenerCollection ) {
    $this->eventListenerCollection = $eventListenerCollection;
}

public function getCollection() {
    return $this->addToListenerCollection()->getCollection();
}

private function addToListenerCollection() {

    $this->eventListenerCollection->registerCallback( 'do.something', function() {
        // Do something
    } );

    $this->eventListenerCollection->registerListener( 'notify.bar', new BarListener() );

    return $this->eventListenerCollection;
}

}, (*6)

```php
$eventDispatcherFactory = new EventDispatcherFactory();

$listenerCollectionRegistry = new ListenerCollectionRegistry(
    $eventDispatcherFactory->newGenericEventListenerCollection()
);

$eventDispatcher = $eventDispatcherFactory->newGenericEventDispatcher();
$eventDispatcher->addListenerCollection( $listenerCollectionRegistry );

class Foo {

    use EventDispatcherAwareTrait;

    public function doSomething() {

        // No context
        $this->eventDispatcher->dispatch( 'do.something' );

        $dispatchContext = new DispatchContext();
        $dispatchContext->set( 'dosomethingelse', new \stdClass );

        // Using `DispatchContext`
        $this->eventDispatcher->dispatch( 'notify.bar', $dispatchContext );

        // Using an array as context which is later converted into
        // a `DispatchContext`
        $this->eventDispatcher->dispatch( 'notify.foo', [ 'Bar' => 123 ] );
    }
}

$instance = new Foo();
$instance->setEventDispatcher( $eventDispatcher );
$instance->doSomething();

Contribution and support

If you want to contribute work to the project please subscribe to the developers mailing list and have a look at the contribution guidelinee. A list of people who have made contributions in the past can be found here., (*7)

Tests

The library provides unit tests that covers the core-functionality normally run by the continues integration platform. Tests can also be executed manually using the PHPUnit configuration file found in the root directory., (*8)

Release notes

  • 1.1.0 (2019-01-27), (*9)

    • Allowed EventDispatcher::dispatch to take an array as context object
    • Added the EventNotDispatchableException and Subscriber interface
    • Added the EventDispatcherAwareTrait class
  • 1.0.0 initial release (2015-03-25), (*10)

License

GNU General Public License 2.0 or later., (*11)

The Versions

27/01 2018

dev-master

9999999-dev https://github.com/onoi/event-dispatcher

A minimalistic interface to relay generic events to registered listeners

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

  • php >=5.3.2

 

events listener

26/03 2015

1.0.0

1.0.0.0 https://github.com/onoi/event-dispatcher

A minimalistic interface to relay generic events to registered listeners

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.2

 

events listener