viloveul/event

Event Dispatcher of Viloveul

v1.1.0 2019-06-19 03:06 UTC

This package is auto-updated.

Last update: 2024-04-19 13:53:40 UTC


README

Build Status Total Downloads Latest Stable Version

Installation

make sure your php version > 7.0

composer require viloveul/event

How

require __DIR__ . '/vendor/autoload.php';

class MyEvent
{
    /**
     * @var string
     */
    public $name = 'foo';
}

class MyListener
{
    /**
     * @param MyEvent $event
     */
    public function __invoke(MyEvent $event)
    {
        if ($event->name === 'foo') {
            throw new Exception("foo");
        } else {
            throw new Exception("bar");
        }
    }
}

$provider = new Viloveul\Event\Provider();
$provider->addListener(new MyListener());

$dispatcher = new Viloveul\Event\Dispatcher($provider);
$dispatcher->dispatch(new MyEvent());