2017 © Pedro Peláez
 

library signal

Event Dispatcher Library

image

lucid/signal

Event Dispatcher Library

  • Thursday, September 15, 2016
  • by iwyg
  • Repository
  • 1 Watchers
  • 0 Stars
  • 48 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Event Dispatcher Library

Author Source Code Software License, (*1)

Build Status Code Coverage HHVM, (*2)

Requirements

php >= 5.6

Installation

$ composer require lucid/signal

Usage

<?php

use Lucid\Signal\EventInterface;
use Lucid\Signal\EventDispatcher;

$dispatcher = new EventDispatcher;

$dispatcher->addHandler('my_event', function (EventInterface $event) {
    // do something
});

Event Handlers

Eventhandlers can be any callable but must accept an instance of EventInterface as their first argument., (*3)

Using handlers the implement the HandlerInterface will automatically call the handleEvent method on the handler if the event is dispatched., (*4)

<?php

use Lucid\Signal\EventInterface;
use Lucid\Signal\HandlerInterface;
use Lucid\Signal\EventDispatcher;

class MyHandler implements HandlerInterface
{
    public function handleEvent(EventInterface $event)
    {
        // do something
    }
}
<?php

$dispatcher = new EventDispatcher;
$handler = new MyHandler;

$dispatcher->addHandler('my_event', $handler);

MyHandler::handleEvent will now be called when my_event is fired., (*5)

Event Delegation

Events are fired subsequentially unless all handlers where adressed or until the Event object is being stopped. You can stop the eventdelegation in your handler by calling $event->stop()., (*6)

Custom Events

Event objects can be referred to message objects. You can easily create your custom message objects by implementing the EventInterface interface or extending the Event base class., (*7)

<?php

namespace Acme\Message;

use Lucid\Signal\Event;

class SysMessage extends Event
{
    private $message;

    public function setMessage($message)
    {
        $this->message = $message;
    }

    public function getMessage()
    {
        return $this->message;
    }
}

The Versions

15/09 2016

dev-develop

dev-develop

Event Dispatcher Library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar iwyg

events pubsub eventing

23/04 2016

dev-master

9999999-dev

Event Dispatcher Library

  Sources   Download

MIT

The Development Requires

by Avatar iwyg

events eventing

12/04 2016

v0.0.1

0.0.1.0

Event Dispatcher Library

  Sources   Download

MIT

The Development Requires

by Avatar iwyg

events eventing