All Projects → brick → event

brick / event

Licence: MIT license
An event dispatching library for PHP

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to event

event-dispatcher
💥 Best events support (symfony/event-dispatcher) to Nette Framework (@nette)
Stars: ✭ 23 (+21.05%)
Mutual labels:  events, event-dispatcher
Event Dispatcher
The EventDispatcher component provides tools that allow your application components to communicate with each other by dispatching events and listening to them.
Stars: ✭ 7,946 (+41721.05%)
Mutual labels:  events, event-dispatcher
ikisocket
🧬 WebSocket wrapper with event management for Fiber https://github.com/gofiber/fiber. Based on Fiber WebSocket and inspired by Socket.io
Stars: ✭ 92 (+384.21%)
Mutual labels:  events
dead-simple
💀💡 Dead simple PubSub and EventEmitter in JavaScript
Stars: ✭ 21 (+10.53%)
Mutual labels:  events
code-of-conduct
rubyberlin.github.io/code-of-conduct/
Stars: ✭ 60 (+215.79%)
Mutual labels:  events
search-insights.js
Library for reporting click, conversion and view metrics using the Algolia Insights API
Stars: ✭ 39 (+105.26%)
Mutual labels:  events
kstreams-des-demo
Kafka Streams demo project containing Derivative Events, the Processor Api and Wall-clock examples
Stars: ✭ 24 (+26.32%)
Mutual labels:  events
yii-event
Events for Yii applications
Stars: ✭ 12 (-36.84%)
Mutual labels:  events
kalend
React calendar component with support for multiple views and events
Stars: ✭ 135 (+610.53%)
Mutual labels:  events
KittyEvents
Super simple event system on top of ActiveJob
Stars: ✭ 20 (+5.26%)
Mutual labels:  events
Chordly
Chordly is a javascript library that may be used to detect and act upon key sequences entered by a user.
Stars: ✭ 14 (-26.32%)
Mutual labels:  events
consolidated-events
Manage multiple event handlers using few event listeners
Stars: ✭ 44 (+131.58%)
Mutual labels:  events
angular-PubSub
Angular 1.x implementation of the Publish–Subscribe pattern.
Stars: ✭ 32 (+68.42%)
Mutual labels:  events
GETProtocolCore
🎫 Contract overview and definition of GET Protocol's NFTs
Stars: ✭ 31 (+63.16%)
Mutual labels:  events
commons.openshift.org
Repository for OpenShift Commons Community Site
Stars: ✭ 31 (+63.16%)
Mutual labels:  events
iranian-calendar-events
Fetch Iranian calendar events (Jalali, Hijri and Gregorian) from time.ir website
Stars: ✭ 28 (+47.37%)
Mutual labels:  events
vue-bus
Tiny simple central event bus plugin for Vue.js
Stars: ✭ 50 (+163.16%)
Mutual labels:  events
berlinblockchainweek
Website for Berlin Blockchain Week 2018
Stars: ✭ 15 (-21.05%)
Mutual labels:  events
talksearch
🎤 An interactive search experience for video titles and transcripts
Stars: ✭ 24 (+26.32%)
Mutual labels:  events
2018
Webend v4.5.26
Stars: ✭ 24 (+26.32%)
Mutual labels:  events

Brick\Event

A simple event dispatching mechanism.

Build Status Coverage Status Latest Stable Version License

Introduction

This library helps to write extensible software by plugging in external listeners to events dispatched by an application.

Installation

This library is installable via Composer:

composer require brick/event

Requirements

This library requires PHP 7.1 or later.

Overview

This package provides the EventDispatcher. The dispatcher dispatches events: an event is a unique string along with optional parameters. The events are intercepted by listeners: any callable can be an event listener.

Basic usage

Let's instantiate a dispatcher:

use Brick\Event\EventDispatcher;

$dispatcher = new EventDispatcher();

And add a few listeners:

$dispatcher->addListener('startup', function() {
    echo 'Caught startup event';
});

$dispatcher->addListener('shutdown', function() {
    echo 'Caught shutdown event';
});

Now, let's dispatch some events:

$dispatcher->dispatch('startup'); // will display "Caught startup event"
$dispatcher->dispatch('shutdown'); // will display "Caught shutdown event"

Any additional parameters you pass to dispatch() are forwarded to the listeners:

$dispatcher->addListener('test', function($a, $b) {
    echo "Caught $a and $b";
});

$dispatcher->dispatch('test', 'Hello', 'World'); // will display "Caught Hello and World"

Setting priorities

By default, the listeners are called in the order they have been registered. It is possible to bypass this natural order by passing a priority to addListener():

$dispatcher->addListener('startup', function() { ... }, 10);

The default priority is 0. The listeners with the highest priority will be called first in the chain. Two listeners with the same priority will be called in the order they have been registered.

Stopping event propagation

Any listener can decide that the event should not be propagated to further listeners in the chain, by returning false:

$dispatcher->addListener('startup', function() {
    // ...

    return false;
});

The dispatcher will then break the chain and no further listeners will be called for this event.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].