Download the PHP package stougeiro/event without Composer
On this page you can find all versions of the php package stougeiro/event. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package event
Event
Lightweight event dispatcher with wildcard pattern matching and automatic deduplication. Dispatch string-based events, register invokable listeners, and load configurations from PHP files — all with zero cache overhead.
✨ Features
-
String-based event dispatching
Events are simple strings, no classes or enums required. -
Wildcard pattern matching
Register listeners onpost.*to catch allpost.created,post.updated, etc. -
Automatic deduplication
Same listener instance onpost.createdandpost.*executes only once per dispatch. -
File-based listener loading
Load listener mappings from PHP config files for clean bootstrapping. -
High performance
Native merge by class name, no cache layers, no auxiliary structures. -
Framework-agnostic
Works with any PHP 8.2+ project. - Global helpers
event()andevents()for quick dispatch without instantiation.
📦 Installation
📐 Event Name Rules
Event names must follow a strict pattern for consistency and fast regex matching.
Structure
Segments: alphanumeric characters only (a-z, A-Z, 0-9)
Separators: ., :, or -
Wildcard: * allowed alone or at the end
Valid Names
| Name | Description |
|---|---|
* |
Global wildcard (all events) |
post.created |
Standard dot notation |
user:registered |
Colon separator |
order-item.placed |
Hyphen separator |
app.module.event |
Multiple segments |
post.* |
Wildcard at end |
user:* |
Wildcard with colon |
Invalid Names
| Name | Reason |
|---|---|
post created |
Space not allowed |
.post.created |
Cannot start with separator |
post.created. |
Cannot end with separator |
post..created |
Double separator |
post.*.detail |
Wildcard not at end |
🚀 Usage
Two paths: instance or global helper.
Path 1: Instance
Path 2: Global helpers
| Function | Returns | Use |
|---|---|---|
events() |
EventManager |
Register listeners, load config |
event($name, $data) |
void |
Dispatch shorthand |
Both share the same EventManager instance — listeners registered via events() are triggered by event().
Wildcard listeners
Deduplication: same listener, multiple events
Load from file
Global wildcard: listen to all events
🧠 Why?
Event systems don't need to be complex. This library provides a dispatcher that combines string-based events, wildcard matching, and automatic deduplication — without cache layers, queues, or heavy abstractions.
By using class names as merge keys, duplicate listeners are eliminated naturally at registration and resolution time. The result is a predictable, high-performance dispatcher that works in any PHP 8.2+ environment.
🤝 Contributions
Contributions are welcome. Feel free to open issues or submit pull requests.
