1. Go to this page and download the library: Download coders/events 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/ */
coders / events example snippets
Coders\Events\EventBus;
use Coders\Events\Event;
$eventBus = new EventBus();
// Simple listener
$eventBus->on('user.registered', function(Event $event) {
echo "New user: " . $event->data['name'] . "\n";
});
// Listener with target
$eventBus->on('notification', function(Event $event) {
echo "Email sent to: " . $event->data['email'] . "\n";
}, 'email');
$eventBus->on('notification', function(Event $event) {
echo "SMS sent to: " . $event->data['phone'] . "\n";
}, 'sms');
// Simple event
$event = new Event('user.registered', [
'name' => 'John Doe',
'email' => '[email protected]'
]);
$eventBus->emit($event);
// Event with specific target
$emailEvent = new Event('notification', [
'email' => '[email protected]',
'message' => 'Welcome!'
], 'email');
$eventBus->emit($emailEvent);