PHP Classes

Event router: Register event handlers and dispatch events

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 44 All time: 10,834 This week: 40Up
Version License PHP version Categories
event-router-php 1.0MIT/X Consortium ...7.4Algorithms, Libraries, Language, PHP 7
Description 

Author

This package can register event handlers and dispatch events.

It provides a class that can register event handler callback functions associated with a given event name.

The package can also dispatch an event with a given name by calling all callback functions registered to handle events with that name.

Picture of Smoren  Freelight
  Performance   Level  
Innovation award
Innovation award
Nominee: 16x

 

Details

event-router

Packagist PHP Version Support Scrutinizer Code Quality Code Coverage Build and test License: MIT <!-- Coverage Status -->

Router for flexible configuring of event handling behaviors.

How to install to your project

composer require smoren/event-router

Unit testing

composer install
composer test-init
composer test

Usage

use Smoren\EventRouter\Components\EventRouter;
use Smoren\EventRouter\Interfaces\EventInterface;
use Smoren\EventRouter\Events\Event;
use Smoren\EventRouter\Structs\EventConfig;
use Smoren\EventRouter\Loggers\ArrayLogger;

$router = new EventRouter(10, new ArrayLogger());
$router
    ->on(new EventConfig('origin1'), function(EventInterface $event) {
        return null;
    })
    ->on(new EventConfig('origin1', 'recursive_single'), function(EventInterface $event) {
        return new Event('origin2', 'test');
    })
    ->on(new EventConfig('origin1', 'recursive_multiple'), function(EventInterface $event) {
        return [
            new Event('origin1', 'recursive_single'),
            new Event('origin2', 'test'),
        ];
    })
    ->on(new EventConfig('origin2'), function(EventInterface $event) {
        return null;
    });

$router->send(new Event('origin1', 'first'));

  Files folder image Files (27)  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (7 directories)
Files folder imagetests (3 files, 2 directories)
Accessible without login Plain text file codeception.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:0
All time:10,834
This week:40Up