1. Go to this page and download the library: Download echo-fusion/eventmanager 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/ */
echo-fusion / eventmanager example snippets
use EchoFusion\Contracts\EventManager\EventInterface;
use EchoFusion\EventManager\BaseEvent;
use EchoFusion\EventManager\EventManager;
// Create an instance of EventManager
$eventManager = new EventManager();
// Define the first listener
$listener1 = function (EventInterface $event) {
echo "Listener 1: The event '" . $event->getName() . "' was triggered!\n";
};
// Define the second listener
$listener2 = function (EventInterface $event) {
echo "Listener 2: The event '" . $event->getName() . "' was triggered!\n";
};
// Attach both listeners to an event named 'user.register'
$eventManager->attach('user.register', $listener1);
$eventManager->attach('user.register', $listener2);
// Create a new event
$event = new class('user.register') extends BaseEvent {
public function __construct(string $name)
{
$this->setName($name);
}
};
// Trigger the 'user.register' event, and both listeners will respond
$eventManager->trigger($event);
final class UserRegistered
{
public function __construct(public readonly string $email) {}
}
$eventManager->attach(UserRegistered::class, function (UserRegistered $event) {
// send the welcome mail to $event->email
});
$eventManager->dispatch(new UserRegistered('[email protected]')); // returns the event
$eventManager->attach('user.register', $sendWelcomeMail, 10); // higher priority runs first; default 0
$eventManager->attach('user.register', $audit, -10); // runs last; equal priorities keep attach order
$eventManager->detach('user.register', $audit); // true when it was attached (same callable)
$eventManager->hasListeners('user.register'); // bool
$eventManager->getListeners('user.register'); // callables attached under that key, in call order
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.