1. Go to this page and download the library: Download h2sf/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/ */
h2sf / events example snippets
$logger = new BasicLogger(__DIR__.'/logs.log');
// Initilize new instance
// Logger is er($logger);
// Optional, set by default
// This will cause execution of consumers at the moment of queueEvent()
$eventManager->setConsumeImmediately(true);
// If you want...
$eventManager->setThrowOnFirstConsumerError(true);
// It will use logger first and then throw
// Anonymous classes can be registered - as well as just objects implementing the ConsumerInterface
$eventManager->addListener(new class implements ConsumerInterface {
public function consumeEvent(EventInterface $event)
{
echo "[ANY EVENT] ";
}
});
// Callables can be registered
$eventManager->addListener(function(EventInitialized $event) use($bootstrap) {
echo "[INITIALIZED, running at {$bootstrap->getTargetTPS()} TPS]\n";
});
// And you post / execute consumers
$eventManager->queueEvent(new \Siarko\CliBootstrap\Events\EventInitialized());
// Also, if setConsumeImmediately(false), consumers won't be executed.
// Events will be queued and then consumers will execute at once with
$eventManager->consumeEvents();
// If you want to postpone execution of a selected event, use
$eventManager->queueEvent(new \Siarko\CliBootstrap\Events\EventInitialized(), postpone: true);
//It will execute the consumers for this event either with next normal event execution of with
$eventManager->consumeEvents();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.