MVC Micro Framework

Event Dispatcher

Event Dispatcher is another component in MVC Micro Framework. It is a simple implementation of design pattern Observer.

Event Dispatcher

Event

Event Dispatcher is a simple implementation of the Observer design pattern and is based on PSR-14 standards. It's easy to use. Just create Event and Dispatcher objects.
 1$this->eventDispatcher = new Dispatcher();  2$this->callDatabase = new Event("database");  3  4$this->eventDispatcher->attach($this->callDatabase, array($this, 'getDatabaseInstance'));
 1public function template()  2{  3$this->eventDispatcher->dispatch($this->callDatabase);  4}

Dispatch

The Dispatcher then registers the Listener, which is any executable part of the code. In addition, it is sufficient to call the Dispatcher object method Dispatch anywhere in the code, which informs all interested listeners . It is also possible to stop the promotion of any event. So if a given event occurs listeners will not be alerted.