1. Go to this page and download the library: Download kornheiser/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/ */
kornheiser / events example snippets
use Kornheiser\Event\Event;
class NewMessageEvent implements Event {
public function __construct(
public string $text,
public int $time,
public string $senderMail
): void {}
}
use Kornheiser\Event\Handler;
class NewMessageHandler implements Handler {
public function onHandle(Event $ev): void {
var_dump($ev->text, $ev->time, $ev->senderMail);
}
}
use Kornheiser\Event\CallableHandler;
$callableHandler = new CallableHandler(function(Event $ev) {
echo $ev->senderMail . ": " . $ev->text;
});
use Kornheiser\Event\TargetedHandler;
$handler1 = new TargetedHandler(NewMessageEvent::class, new NewMessageHandler());
$handler2 = new TargetedHandler(NewMessageEvent::class, $callableHandler);
use Kornheiser\Event\EventManager;
$invoker = new EventManager();
$invoker->addHandler($handler1);
$invoker->addHandler($handler2);
$invoker->call(new NewMessageEvent(text: "hello world", time: time(), senderMail: "some programmer"));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.