⚠️ DEPRECATED — Useinitphp/eventsinsteadAs part of the InitPHP package consolidation, this package has been merged into
initphp/eventsstarting with version 2.0. The new package bundles the sameEventEmitterprimitive plus the higher-levelEvents/Eventfacade.This repository is kept read-only for historical reference. The final release (
1.0.1) ships a bug fix forEventEmitter::emit()(see below) but no further updates will be released.
Update your
composer.json:- "initphp/event-emitter": "^1.0", + "initphp/events": "^2.0"Your existing imports keep working:
initphp/events:^2.0ships aclass_aliasso\InitPHP\EventEmitter\EventEmitterand\InitPHP\EventEmitter\EventEmitterInterfaceremain resolvable.When you next touch the code, prefer the canonical namespace:
// Before use InitPHP\EventEmitter\EventEmitter; // After use InitPHP\Events\EventEmitter;Composer declares a
replacefrominitphp/events:^2.0toinitphp/event-emitter, so the two packages will not be installed side-by-side.Version
1.0.1of this package contains a single bug fix inEventEmitter::emit(): the inner loop now correctly passes each individual$listenertocall_user_func_array, instead of the surrounding$listenersarray. Before this fix, emitted events fired no listeners.
This library has been designed to emit events in its simplest and simplest form.
- PHP 5.6 or higher
composer require initphp/event-emitter
or Manuel Installation :
Download this repository. And include the src/Init.php file in your project.
require_once "vendor/autoload.php";
use InitPHP\EventEmitter\EventEmitter;
$events = new EventEmitter();
$events->on('hello', function ($name) {
echo 'Hello ' . $name . '!' . PHP_EOL;
}, 99);
$events->on('hello', function ($name) {
echo 'Hi ' . $name . '!' . PHP_EOL;
}, 10);
// Emit
$events->emit('hello', ['World']);Copyright © 2022 MIT License