crcms/event

event

1.0.2 2019-10-28 12:33 UTC

This package is auto-updated.

Last update: 2024-10-28 23:46:29 UTC


README

Set the scheduler

Example::setDispatcher(new \CrCms\Event\Dispatcher);

Register event

Example::registerEvent('event1',$listener);

Push event listener

Example::pushEvent('event1',$listener);

Listening method


//first
$listener => ExampleListener1::class@listen

//second
$listener => ExampleListener2::class

//third
$listener => function($object) {
    ...
}

class ExampleListener1
{
    public function listen($object)
    {
        ...
    }
}

class ExampleListener2
{
    public function handle($object)
    {
        ...
    }
}

function($object) {
    ...
}

Event trigger

class Example {

    use CrCms\Event\HasEvents;
    
    # Set events
    public static function events() : array
    {
        return ['event1','event2'];
    }
    
    public function example()
    {
        # Trigger event
        Example::fireEvent('event1',$listener);
    }
}