Skip to content
This repository was archived by the owner on May 24, 2026. It is now read-only.

InitPHP/EventEmitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

InitPHP EventEmitter

⚠️ DEPRECATED — Use initphp/events instead

As part of the InitPHP package consolidation, this package has been merged into initphp/events starting with version 2.0. The new package bundles the same EventEmitter primitive plus the higher-level Events / Event facade.

This repository is kept read-only for historical reference. The final release (1.0.1) ships a bug fix for EventEmitter::emit() (see below) but no further updates will be released.

Migration

  1. Update your composer.json:

    - "initphp/event-emitter": "^1.0",
    + "initphp/events": "^2.0"
  2. Your existing imports keep working: initphp/events:^2.0 ships a class_alias so \InitPHP\EventEmitter\EventEmitter and \InitPHP\EventEmitter\EventEmitterInterface remain resolvable.

  3. When you next touch the code, prefer the canonical namespace:

    // Before
    use InitPHP\EventEmitter\EventEmitter;
    
    // After
    use InitPHP\Events\EventEmitter;

Composer declares a replace from initphp/events:^2.0 to initphp/event-emitter, so the two packages will not be installed side-by-side.

emit() bug fix in 1.0.1

Version 1.0.1 of this package contains a single bug fix in EventEmitter::emit(): the inner loop now correctly passes each individual $listener to call_user_func_array, instead of the surrounding $listeners array. Before this fix, emitted events fired no listeners.


This library has been designed to emit events in its simplest and simplest form.

Requirements

  • PHP 5.6 or higher

Installation

composer require initphp/event-emitter

or Manuel Installation :

Download this repository. And include the src/Init.php file in your project.

Usage

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

Credits

License

Copyright © 2022 MIT License