1. Go to this page and download the library: Download pleets/php-event-dispatcher 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/ */
pleets / php-event-dispatcher example snippets
use Pleets\EventDispatcher\Event;
class DepositEvent extends Event
{
public string $text;
protected string $amount;
private string $currency = 'USD';
public function __construct($amount)
{
$this->amount = $amount;
$this->text = 'We are preparing your deposit: '.$this->amount.$this->currency;
}
}
use Pleets\EventDispatcher\Event;
use Pleets\EventDispatcher\Listener;
class SendDepositNotification extends Listener
{
public function handle(Event $event): void
{
$event->text = 'Your deposit was done!';
}
}
$provider = new ListenerProvider();
$deposit = new DepositEvent('127.00');
$provider->subscribe($deposit, new SendDepositNotification());
$dispatcher = new Dispatcher($provider);
$dispatcher->dispatch($deposit);