2017 © Pedro Peláez
 

library event-emitter

Event Emitter

image

krak/event-emitter

Event Emitter

  • Sunday, March 19, 2017
  • by ragboyjr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 72 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Event Emitter

Simple event emitter package with a lot of flexibility. Inspired by the Evenement library, EventEmitter provides a simple interface for adding and emitting events., (*1)

Installation

Install with composer at krak/event-emitter, (*2)

Usage

<?php

$emitter = Krak\EventEmitter\emitter(); // creates the default emitter instance
$emitter->on('event', function($arg) {
    echo "Hello $arg\n";
});
$emitter->emit('event', "World");

This is the event emitter interface:, (*3)

<?php

interface EventEmitter {
    public function on($event, $listener);
    public function once($event, $listener);
    public function removeListener($event, $listener);
    public function removeAllListeners($event = null);
    public function listeners($event);
    public function emit($event, ...$arguments);
}

Event Listeners

You can add event listener classes by implementing the EventListener interface., (*4)

<?php

use Krak\EventEmitter\EventListener;

class AcmeListener implements EventListener
{
    public function handle($param) {

    }
}

You can then add this into the emitter via:, (*5)

<?php

$emitter->on('event', new AcmeListener());

Custom Invocation

The default emitter supports custom invocations via the Krak\Invoke library. You can easily pass in a custom invoker which provides flexibility with how your listeners will be invoked., (*6)

<?php

use Krak\EventEmitter;

// this creates an emitter that will support container services as listeners
$invoke = new Krak\Invoke\ContainerInvoke(EventEmitter\emitterInvoke(), $container);
$emitter = Krak\EventEmitter\emitter($invoke);
$emitter->on('event', 'service_id');
$emitter->emit('event', 1);

The Versions

19/03 2017

dev-master

9999999-dev

Event Emitter

  Sources   Download

MIT

The Requires

 

The Development Requires

19/03 2017

v0.1.0

0.1.0.0

Event Emitter

  Sources   Download

MIT

The Requires

 

The Development Requires