Download the PHP package tweekersnut/event-dispatcher without Composer
On this page you can find all versions of the php package tweekersnut/event-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tweekersnut/event-dispatcher
More information about tweekersnut/event-dispatcher
Files in tweekersnut/event-dispatcher
Package event-dispatcher
Short Description Provides tools that allow your application components to communicate with each other by dispatching events and listening to them. Supports both Laravel and core PHP.
License MIT
Informations about the package event-dispatcher
Event Dispatcher
A flexible and powerful event dispatcher package for PHP that allows your application components to communicate with each other by dispatching events and listening to them. Supports both Laravel and core PHP.
Features
- ๐ Simple and intuitive API
- ๐ฏ Priority-based event listeners
- ๐ฆ Event subscribers for grouping related listeners
- ๐ Event propagation control
- ๐จ Works with both Laravel and core PHP
- ๐ช Type-safe with interfaces and contracts
- ๐งช Easy to test
- ๐ Well documented with examples
Installation
For Laravel Projects
Install the package via Composer:
The service provider will be automatically registered via Laravel's package discovery.
For Core PHP Projects
-
Install the package via Composer:
- Include the Composer autoloader in your project:
For Development/Testing
Clone the repository and install dependencies:
Run the examples:
Or use the interactive example runner:
Quick Start
Core PHP
Laravel
The service provider is automatically registered via Laravel's package discovery.
Getting Started
Step 1: Installation
For Laravel:
For Core PHP:
Step 2: Try the Examples
After installation, you can run the included examples to see the package in action:
Step 3: Start Using in Your Project
Core PHP:
Laravel:
Usage
Basic Event Dispatching
Using Event Objects
Custom Event Classes
Event Listeners
Closure Listeners
Class-based Listeners
Priority-based Listeners
Listeners with higher priority execute first:
Event Subscribers
Group related event listeners together:
Stopping Event Propagation
Managing Listeners
Laravel Integration
Publishing Configuration
Using Dependency Injection
Auto-registering Subscribers
In config/event-dispatcher.php:
Examples
Quick Start
Run the interactive example runner:
Or run individual examples directly:
Check the examples directory for more detailed examples:
-
Core PHP Examples:
examples/core-php/basic-usage.php- Basic event dispatchingexamples/core-php/listener-classes.php- Using listener classesexamples/core-php/subscriber-example.php- Event subscribers
- Laravel Examples:
examples/laravel/README.md- Comprehensive Laravel integration guide
Testing
API Reference
EventDispatcher
listen(string $eventName, $listener, int $priority = 0): void- Register an event listenersubscribe($subscriber): void- Register an event subscriberdispatch($event, $payload = null)- Dispatch an eventforget(string $eventName, $listener = null): void- Remove listenershasListeners(string $eventName): bool- Check if event has listenersgetListeners(string $eventName): array- Get all listeners for an eventgetEvents(): array- Get all registered eventsclear(): void- Clear all listeners
Requirements
- PHP 7.4 or higher
- Laravel 8.x, 9.x, 10.x, or 11.x (for Laravel integration)
License
The MIT License (MIT). Please see License File for more information.
Credits
- Tweekersnut Network - [email protected]
Support
For issues, questions, or contributions, please visit the GitHub repository.