2017 © Pedro Peláez
 

library event-dispatcher

Event dispatcher package

image

slince/event-dispatcher

Event dispatcher package

  • Sunday, June 24, 2018
  • by slince
  • Repository
  • 1 Watchers
  • 3 Stars
  • 14 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Event Dispatcher

Build Status Coverage Status Latest Stable Version Scrutinizer, (*1)

Installation

Install via composer., (*2)

$ composer require slince/event-dispatcher

Usage

Creates a event dispatcher

$dispatcher = new Slince\EventDispatcher\Dispatcher();

Adds a listener for the specified event

There are two types of listeners: callable and Slince\EventDispatcher\Listener, (*3)

  • Slince\EventDispatcher\Listener
use Slince\EventDispatcher\ListenerInterface;

class FooListener implements ListenerInterface
{
     public function handle(Event $event)
     {
         //do something
     }
}

$dispatcher->addListener('foo-event-name', new FooListener());
  • callable
$dispatcher->addListener('foo-event-name', function(Event $event){
    //do something
});

Add a subscriber

use Slince\EventDispatcher\SubscriberInterface;

class FooSubscriber implements SubscriberInterface
{
     public static function getSubscribedEvents(Event $event)
     {
        return [
            'foo' => 'onFoo',
            'bar' => 'onBar'
        ];
     }

    public function onFoo(Event $event)
    {
      //do something
    }

    public function onBar(Event $event)
    {
       //do something
    }
}

$dispatcher->addSubscriber(new FooSubscriber());

Dispatches the event to the registered listeners

Just provides the event name., (*4)

$dispatcher->dispatch('foo-event-name');

You can also dispatch with an event instance., (*5)

$dispatcher->dispatch(new Event('foo-event-name'));

Propagation

You can call stopPropagation to stop event propagation on the event instance., (*6)

$dispatcher->addListener('foo-event-name', function(Event $event){
    $event->stopPropagation();
});

$emitter->addListener('foo-event-name', function ($event) {
    // This will not be triggered
});

$dispatcher->dispatch('foo-event-name');

Checks whether propagation is stopped, (*7)

```php $event = new Event('foo-event-name'); $dispatcher->dispatch($event);, (*8)

$event->isPropagationStopped(); ```, (*9)

### License, (*10)

The MIT license. See MIT, (*11)

The Versions

24/06 2018

dev-master

9999999-dev

Event dispatcher package

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by tao

subscriber emitter event listener event dispatcher observer pattern

21/06 2018

2.0.0

2.0.0.0

Event dispatcher package

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by tao

subscriber emitter event listener event dispatcher observer pattern

26/05 2017

1.0.2

1.0.2.0

The event dispatcher

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by tao

subscriber emitter event listener event dispatcher observer pattern

05/05 2017

1.0.1

1.0.1.0

The event dispatcher

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by tao

subscriber emitter event listener event dispatcher observer pattern

16/05 2016

1.0.0

1.0.0.0

Slince event dispatcher component

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5.9

 

The Development Requires

by tao