PHP Classes


Recommend this page to a friend!
  Classes of Smoren Freelight   Event router   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Event router
Register event handlers and dispatch events
Author: By
Last change:
Date: 7 months ago
Size: 1,996 bytes


Class file image Download


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


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());
    ->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'));