Download the PHP package initphp/events without Composer

On this page you can find all versions of the php package initphp/events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package events

InitPHP Events

A small, dependency-free event / hook library for PHP. Ships both a high-level dispatcher with WordPress-style do_action-like semantics (stop the chain when a listener returns false, simulate mode, debug log) and a plain low-level EventEmitter you can instantiate and pass around like any other object.

CI Latest Stable Version Total Downloads License PHP Version Require

Heads-up — v2.0 fixes a long-standing priority-ordering bug. In 1.x, listeners ran in the order they were registered, not in the order their priorities asked for. v2.0 makes priority honour its name. If your 1.x code happened to register listeners in ascending priority order, the visible behaviour does not change; if it didn't, please re-read Priorities and ordering and the v2.0 changelog.

At a glance

Everything is in a single PSR-4 namespace (InitPHP\Events\) and has zero runtime dependencies.

Requirements

Requirement Version
PHP >= 5.6 (runtime); PHP >= 7.3 to run the test suite (PHPUnit 9.6)
Extensions none
Composer dependencies none

Installation

If you are coming from initphp/event-emitter, replace your dependency — initphp/events declares a Composer replace for it and ships a class alias so the old fully-qualified names still resolve. See Migration for details.

Quick start

Output:

The listener registered with priority 99 runs before the one with priority 100 — lower numeric value means runs first. The three named constants Events::PRIORITY_HIGH (10), Events::PRIORITY_NORMAL (100), and Events::PRIORITY_LOW (200) exist for readability.

Passing arguments to listeners

Stopping the chain

A listener that returns boolean false halts the chain — subsequent listeners are not invoked and trigger() itself returns false. This is the same convention as WordPress's apply_filters short-circuit:

Working with Event directly

If you prefer a dispatcher you instantiate and pass around (easier to test, easier to scope, no global state), use Event:

Event and Events expose the same surface — Events::on(...) simply forwards to a shared Event instance.

Working with the low-level EventEmitter

For libraries that want the smallest possible surface, the underlying emitter is also public:

Differences from Event:

EventEmitter is what Event is built on. The same instance is reachable via $dispatcher->getEmitter() if you ever need both high-level dispatch and low-level emit on the same listener registry.

Priorities and ordering

Rules:

  1. Lower numeric priority runs first. The names are about importance (high-priority work runs early); the numbers are about position.
  2. Within the same priority, listeners run in registration order (FIFO).
  3. Priority is global per-event — once-listeners and regular listeners are merged into a single priority-sorted queue when an event fires.
  4. Event names are matched case-insensitively: on('User.Created') and emit('user.created') see the same listener.

See docs/04-priorities-and-ordering.md for the full ordering contract, including how once() interacts with the priority queue.

One-shot listeners, removal, and cleanup

The once() contract is honoured even when the chain is stopped by a false return — a one-shot listener that runs (or that would have run, but for a short-circuit earlier in the queue) is dropped after the trigger completes. See docs/05-once-and-removal.md.

Simulate mode and debug log

Event (and therefore Events) carry two opt-in instrumentation modes:

See docs/06-debug-and-simulate.md.

Public API

Class Purpose
InitPHP\Events\Events Static facade; thin shim over a shared Event instance.
InitPHP\Events\Event High-level dispatcher (priority, short-circuit, simulate, debug).
InitPHP\Events\EventEmitter Low-level primitive (on / once / emit / removeListener / clearOnceListeners).
InitPHP\Events\EventEmitterInterface Contract that EventEmitter implements.
Method Class Purpose
trigger(string $name, ...$arguments): bool Event · Events Dispatch with priority + short-circuit semantics.
on(string, callable, int $priority = PRIORITY_NORMAL): self Event · Events · EventEmitter Register a listener.
once(string, callable, int $priority = PRIORITY_NORMAL): self Event · Events · EventEmitter Register a one-shot listener.
off(string, callable): self Event · Events Remove a specific listener (alias for removeListener).
removeListener(string, callable): void EventEmitter Remove a specific listener.
removeAllListeners(?string = null): self/void Event · Events · EventEmitter Wipe one event, or every event.
emit(string, array $args = []): void EventEmitter Low-level dispatch (no short-circuit).
clearOnceListeners(?string = null): void EventEmitter Drop one-shot listeners without invoking them.
listeners(?string = null): array EventEmitter Inspect the current listener registry.
setSimulate(bool): self / getSimulate(): bool Event · Events Toggle / inspect simulate mode.
setDebugMode(bool): self / getDebugMode(): bool Event · Events Toggle / inspect debug mode.
getDebug(): array / clearDebug(): self Event · Events Read / clear the debug log.
getEmitter(): EventEmitter Event · Events Access the backing emitter.
getInstance(): Event Events Return the shared dispatcher.
setInstance(Event): void Events Inject a pre-configured dispatcher.
reset(): void Events Drop the shared instance (tests, lifecycle resets).

Full signatures and exception behaviour: docs/09-api-reference.md.

Migrating from initphp/event-emitter

The standalone initphp/event-emitter package has been merged into this one and is now deprecated. If your code currently uses \InitPHP\EventEmitter\EventEmitter, no source changes are required — this package ships a backwards-compatibility alias:

Composer will not install both packages side-by-side because initphp/events:^2.0 declares a replace for initphp/event-emitter.

When you next touch the code, prefer the new canonical namespace:

The alias is intended as a transition aid and may be removed in a future major release. One important behaviour change that comes with v2.0: in 1.x, EventEmitter::emit() had a bug where the entire listeners array was passed to call_user_func_array instead of each individual listener, so emitted events silently fired no listeners at all. That is fixed in 2.0 — if you had quietly broken emit() calls in 1.x, they will now actually run their listeners.

See docs/07-migration-from-event-emitter.md for the full migration checklist.

Documentation

The full guide lives under docs/:

  1. Getting started
  2. The Events facade
  3. Using EventEmitter directly
  4. Priorities and ordering
  5. Once-listeners, removal, and cleanup
  6. Debug and simulate modes
  7. Migrating from initphp/event-emitter
  8. Recipes (plugin systems, request lifecycle, WordPress-style hooks)
  9. API reference

Development

CI runs the test suite across PHP 7.3 – 8.4 and also lints the source on PHP 5.6 / 7.0 / 7.1 / 7.2 so the php >= 5.6 library contract stays honest.

Contributing & Security

Credits

License

Released under the MIT License.


All versions of events with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package initphp/events contains the following files

Loading the files please wait ...