Skip to content

viloveul/event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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());