Download the PHP package xblabs/ripple without Composer
On this page you can find all versions of the php package xblabs/ripple. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xblabs/ripple
More information about xblabs/ripple
Files in xblabs/ripple
Package ripple
Short Description Ripple is a PHP event dispatcher library that allows you to create event-driven systems by providing a simple and easy-to-use interface for handling events.
License MIT
Informations about the package ripple
Ripple
Ripple is a small, fast PHP event dispatcher. It lets you build event-driven systems with a simple interface for registering listeners and dispatching events, with priorities, propagation control, wildcard subscriptions, one-time listeners, subscriber objects, and PSR-14 interoperability.
An event dispatcher decouples the parts of an application: components communicate through events instead of direct calls, which makes the code more maintainable and flexible.
Features
- Simple event dispatching and handling
- Priority-based ordering (higher priority fires first; equal priority is last-in-first-out)
- Stoppable propagation (cancelable events)
- Wildcard listeners (
user.*,order:*, separator-agnostic) - One-time listeners (
once) - Subscriber objects that declare their handlers in one place
- PSR-14 compatible adapter
- Instance or static/singleton usage
- Fully unit-tested; ordering and reflection are resolved once at registration, not on every dispatch
Requirements
- PHP 8.1+
Installation
Usage
Dispatching events
Event names are opaque strings. No character is special —
user.login,user:loginanduser/loginare all just names. (In 1.x a:was reserved for the aggregate system; that is no longer the case. See UPGRADE.md.)
Listeners
A listener is any callable. By default it receives the Event object.
If a closure declares more than one parameter and its first parameter is not named e or event, Ripple spreads
the event's params as positional arguments instead of passing the Event. You can force this with the fourth argument
to dispatch():
Priorities
Default priority is 0. Higher priorities fire first; listeners with equal priority fire last-in-first-out.
Stopping propagation
One-time listeners
once() fires a listener at most once, then removes it. (A once listener that is never reached — e.g. propagation was
stopped before it — is retained for a future dispatch.)
Wildcard listeners
Wildcard patterns use * to match any run of characters, including your separator of choice.
Exact and wildcard listeners compose in a single dispatch and are ordered together by priority (on a tie, exact listeners fire before wildcard ones).
Subscriber objects
A subscriber declares all the events it handles in one place. Keys may contain * (registered as a wildcard).
Managing listeners
Custom event class
Static / singleton usage
DispatcherStatic proxies a single shared dispatcher. It can be reset or injected, which is useful in tests.
PSR-14 interoperability
Event implements Psr\EventDispatcher\StoppableEventInterface. The Psr14\Psr14Dispatcher and Psr14\ListenerProvider
adapters let Ripple act as a PSR-14 EventDispatcherInterface, reusing the same listener storage and priority ordering.
Note the difference between the two APIs: native Ripple dispatches event names and collects listener return values; PSR-14 dispatches an object and returns that same object.
Testing
License
MIT License. See LICENSE for details.