1. Go to this page and download the library: Download ksfraser/event library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ksfraser / event example snippets
use Ksfraser\Event\EventManager;
use Ksfraser\Event\MyCustomEvent;
// Dispatch an event
EventManager::dispatchEvent(new MyCustomEvent($data));
// Add a listener
EventManager::on('user.created', function($event) {
// Handle user creation
});
use Ksfraser\Event\Event;
class UserCreatedEvent extends Event
{
public function __construct(
public readonly int $userId,
public readonly string $email
) {}
}
use Ksfraser\Event\EventManager;
// Add multiple listeners
EventManager::on('order.processed', [$orderService, 'sendConfirmation']);
EventManager::on('order.processed', 'sendOrderNotification');
// Get listener provider for advanced management
$listenerProvider = EventManager::getInstance()->getListenerProvider();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.