2017 © Pedro Peláez
 

library psr7-event-emitter

PSR-7 event-emitter implementation

image

folleah/psr7-event-emitter

PSR-7 event-emitter implementation

  • Tuesday, June 13, 2017
  • by Folleah
  • Repository
  • 1 Watchers
  • 2 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PSR EventManager implementation Scrutinizer Code Quality Code Coverage Build Status Build Status

More about functions, (*1)

Some examples: - Security framework that will prevent saving/accessing data when a user doesn't have permission. - A Common full page caching system - Logging package to track all actions taken within the application, (*2)

Example:, (*3)

use Event\Event;
use Event\EventManager;

$onGreeted = function($var) {
    echo "Hi, {$var}.</br>";
};

$onAsked = function() {
    echo "How are you?</br>";
};

$onGoodbye = function() {
    echo "Bye!</br>";
};

$eventManager = new EventManager;
$event = new Event('acquaintance');

// Listen this event with priority
$eventManager->attach('acquaintance', $onGreeted, 2);
$eventManager->attach('acquaintance', $onAsked, 1);
$eventManager->attach('bye', $onGoodbye);

/**
 * Call created event
 * 
 * output:
 * Hi, Alice.
 * How are you?
 */
$eventManager->trigger($event, null, ['Alice']); // 'Alice' will be passed as argument to the listener callback

/**
 * Create new event and call it
 * 
 * output:
 * Bye!
 */
$newEvent = $eventManager->trigger('bye');

With the stopPropagation() method, you can stop calling the remaining listeners, (*4)

Event stop propagation example:, (*5)

$eventManager = new EventManager;

$helloWorld = function() {
    echo "Hello world!";
};

$eventManager->attach('hello.world', $helloWorld);

$event = $eventManager->trigger('hello.world');
$event->stopPropagation();
// It will not work
$event = $eventManager->trigger('hello.world');

License: MIT, (*6)

The Versions

13/06 2017

dev-master

9999999-dev

PSR-7 event-emitter implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

psr7 event