1. Go to this page and download the library: Download symbiotic/event 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/ */
symbiotic / event example snippets
use Symbiotic\Event\ListenerProvider;
use Symbiotic\Event\EventDispatcher;
$listeners = new ListenerProvider();
$dispatcher = new EventDispatcher($listeners);
$listeners->add(\MyEvents\FirstEvent::class, function(\MyEvents\FirstEvent $event) {
// handle event
});
// Run event
$event = new \MyEvents\FirstEvent();
$dispatcher->dispatch(new \MyEvents\FirstEvent());
use Symbiotic\Event\ListenerProvider;
use Symbiotic\Event\EventDispatcher;
/**
* @var \Closure|string $listener you can wrap the subscribers yourself and handle the event,
* for example, you can pass the event to a class or execute it through your DI container
**/
$listener_wrapper = function($listener) {
return function(object $event) use ($listener) {
// if classname
if(is_string($listener) && class_exists($listener)) {
$listener = new $listener();
return $listener->handle($event);
} elseif(is_callable($listener)) {
return $listener($event);
}
};
};
$listeners = new ListenerProvider($listener_wrapper);
$dispatcher = new EventDispatcher($listeners);
// classname handler
$listeners->add(\MyEvents\FirstEvent::class, \MyEvents\Handlers\FirstHandler::class);
// callable handler
$listeners->add(\MyEvents\FirstEvent::class, function(\MyEvents\FirstEvent $event) {
// handle event
});
// Run event
$event = new \MyEvents\FirstEvent();
$dispatcher->dispatch(new \MyEvents\FirstEvent());
class StopEvent implements Psr\EventDispatcher\StoppableEventInterface
{
// Your logic for stopping
public function isPropagationStopped(): bool
{
return true;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.