Introducing The Event Dispatcher Component
The PtcEvent component provides an observer implementation for your application, allowing the programmer to add and listen for events. Event execution order can be controlled with a priority parameter. The class can add closures and class methods as event listeners. Wildcards are also accepted to watch event listeners execution. There are also library helpers available for this class. The event dispatcher also supports event removal if needed. Event Propagation can also be prevented by returning false inside your event listeners.
Main Features:
- Accepts closures and class methods as event listener
- Supports wildcards for all added events
- Library helpers can be added with the ptc-helpers.php file
- Supports event execution order with the priority parameter
- Supports Event removal if needed
- Can Retrieve a list of added events
- Supports event propagation prevention
- Uses the PtcDebug class to log all event listeners execution
Getting Started
To start using the event dispatcher, download the file simply include the class file PtcEvent.php, and start adding event listeners. Here's a quick and simple example:
-
require_once( 'PtcEvent.php' );
-
- // adding an event listener with a closure as callback
-
PtcEvent::listen( 'form.submit' , function ( $data ){// do some stuffprint "called event with closure as callback!";) );
- // firing an event
For a complete list of options and examples read the full user guide.
**If you like this class, help the project to grow by rating or writing a review at one of the following sites: