/** * @param DispatcherInterface $dispatcher * @param callable $logger */ public function __construct(DispatcherInterface $dispatcher, callable $logger = null) { $dispatcher->addListener('*', array($this, 'loggingListener')); if ($logger === null) { $logger = function ($msg) { error_log($msg); }; } $this->addHelper('*', array($this, 'defaultHelper')); $this->dispatcher = $dispatcher; $this->logger = $logger; }
/** * Attaches a listener to an event * * @param string $eventName The event to listen to. * @param callable $callback A callable function * @param integer $priority The priority at which the $callback executed * * @return boolean * * @since __DEPLOY_VERSION__ */ public function addListener($eventName, callable $callback, $priority = 0) { return $this->dispatcher->addListener($eventName, $callback, $priority); }
/** * Adds an event listener that listens on the specific event. * * @param string $eventName The event to listen on. * @param callable $callback The listener. * @param int $priority The higher this value, the earlier an event * listener will be triggered in the chain (defaults to 0). * @return self */ public function on($eventName, callable $callback, $priority = 0) { $listener = new Listener($eventName, $callback); $this->dispatcher->addListener($eventName, $listener, $priority); return $this; }