5. Events
Event programming is ...TODO ...
The main component is the EventDispatcher
API:
<?php
namespace metadigit\core\event;
interface EventDispatcherInterface {
/**
* Add an Event listener on the specified event
* @param string $eventName the name of the event to listen for
* @param callable $callback the callback function to be invoked
* @param int $priority trigger precedence on the listeners chain (higher values execute earliest)
* @throws \Exception
*/
function listen($eventName, $callback, $priority=1);
/**
* Trigger an Event, calling attached listeners
* @param string $eventName the name of the event
* @param mixed $target Event's target
* @param array $params Event's parameters
* @param Event|null $Event optional custom Event object
* @return Event the Event object
*/
function trigger($eventName, $target=null, array $params=null, $Event=null);
}
The base implementation of EventDispatcherInterface is the metadigit\core\event\EventDispatcher, that add support for XML configuration.
<events>
<event name="dispatcher:controller">
<listeners>
<listener>myproject.apps.web.SessionManager->start</listener>
</listeners>
</event>
<event name="dispatcher:view">
<listeners>
<listener>myproject.apps.web.SessionManager->end</listener>
</listeners>
</event>
</events>
Updated about 1 month ago