All notable changes to initphp/events are documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
EventEmitternow honours priority. Listeners are dispatched in ascending numeric priority order regardless of the order in which they were registered. In 1.x they ran in registration order; theksort()inEventEmitter::listeners()was applied to the wrong array level and effectively did nothing. Code that registered listeners in ascending priority order (the obvious style) sees no visible change. Code that relied on the old "registration order wins" behaviour now sees a different invocation order — that reliance was almost certainly unintentional, but it is a user-visible behaviour change.Event::on()default priority changed fromEvent::PRIORITY_LOW(200) toEvent::PRIORITY_NORMAL(100). Calls that omitted the third argument now run earlier relative to listeners registered with an explicitPRIORITY_LOW. Pass an explicit priority to restore the old positioning.EventEmitterInterfacegainedclearOnceListeners(?string). Anyone shipping their own implementation of this interface must add the method. The bundledEventEmitterof course implements it.- PHPUnit 9.6 requires PHP
>= 7.3for the dev environment. Runtimerequireis unchanged (php: >=5.6); CI lints the source on PHP 5.6 / 7.0 / 7.1 / 7.2 so the runtime contract is verified, but the unit-test suite only runs on PHP 7.3 and newer.
Event::once($name, $callback, $priority)— register a one-shot listener via the high-level dispatcher (previously only available onEventEmitter).Event::off($name, $callback)— remove a specific listener (alias-style; forwards toEventEmitter::removeListener()).Event::removeAllListeners(?string $name)— wipe one event, or every event when called with no arguments.Event::clearDebug()— empty the debug log without dropping the dispatcher.Event::getEmitter()— expose the underlyingEventEmitterfor callers that need both high-level dispatch and low-level emit on the same listener registry.Events::reset()— drop the shared singleton so the next facade call rebuilds a fresh one. Intended for test setUp/tearDown and long-running processes that need a clean slate.Events::setInstance(Event $event)— inject a pre-configured dispatcher, e.g. one with simulate or debug already toggled on.Events::getInstance()is now public (wasprotected).EventEmitter::clearOnceListeners(?string $event)— drop one-shot listeners without invoking them. Used by the high-levelEvent::trigger()loop to keep the once-contract intact when the chain is stopped by afalsereturn.
- Once-listeners registered through
Event(orEvents) now fire at most once. In 1.x,Event::trigger()pulled the listener list viaEventEmitter::listeners()(which includes one-shot listeners) but never cleaned them up, so they fired on every trigger. This is now handled in atry/finallyblock, so the once contract is honoured even when a listener throws or when the chain is halted by afalsereturn. - Typo / Turkish-only docblock on
Event::trigger()— replaced with English documentation consistent with the rest of the ecosystem. Event.phplicense header — was a different format and pointed at a non-existent license URL; aligned with the rest of the package.
- Removed the empty
Event::__destruct()and the defensiveisset()checks it forced on the getters; properties are always initialised by the constructor. - Removed redundant
(bool)casts after the matchingis_bool()guards insetSimulate()/setDebugMode(). - Replaced
::classarguments toclass_exists()/interface_exists()insrc/aliases.phpwith plain string literals — functionally equivalent, but removes the compile-time constant dependency. - 69 unit tests, 110 assertions covering the priority contract,
short-circuit semantics, simulate / debug modes, once + removal,
fluent API, exception paths, the static facade lifecycle, and the
backwards-compatibility alias for
\InitPHP\EventEmitter\*. Coverage: 100% lines / 100% methods / 100% classes acrosssrc/(excludingaliases.php, which is verified by a dedicated BC alias test instead). - PHPStan static analysis at level 8, clean across
src/andtests/. Configuration inphpstan.neon.dist; runtime contract preserved (no scalar type-hints injected).composer analyseruns it. - New CI workflow (
.github/workflows/ci.yml) with four jobs:tests— PHP 7.3 / 7.4 / 8.0 / 8.1 / 8.2 / 8.3 / 8.4 —composer install+phpunit.static-analysis— PHPStan level 8 on PHP 8.3.code-style— PHP-CS-Fixer dry-run on PHP 8.3.lowest-php-syntax— PHP 5.6 / 7.0 / 7.1 / 7.2 —php -lon every source file and a Composer-free autoload smoke test, to keep thecomposer.json: php >= 5.6contract honest.
composer.jsonnow declaresautoload-devfor the test suite,keywords,supportURLs, ascripts.testentry, andconfig.sort-packages. Runtimerequireis unchanged.
- Bundled the low-level
EventEmitterprimitive previously distributed as the separateinitphp/event-emitterpackage, which is now deprecated. A class alias keeps the legacy\InitPHP\EventEmitter\*fully-qualified names working. - Minimum PHP requirement set to 5.6.
- The standalone
initphp/event-emitterpackage was retired; this package declares a Composerreplacefor it.
Pre-1.0.2 history was not maintained in a CHANGELOG.md. Refer to the
Git log for individual fix commits (git log src/Event.php,
git log src/Events.php).