/** * Push the toolbar into the view * . * * @param KEvent A event object */ public function onAfterControllerGet(KEvent $event) { $this->addParameterCommand(); //Render the menubar $document = JFactory::getDocument(); $config = array('menubar' => $this); $menubar = $event->getPublisher()->getView()->getTemplate()->getHelper('menubar')->render($config); $document->setBuffer($menubar, 'modules', 'submenu'); }
/** * Command handler * * @param string The command name * @param object The command context * @return boolean Always returns true */ public function execute($name, KCommandContext $context) { $type = ''; if ($context->caller) { $identifier = $context->caller->getIdentifier(); if ($identifier->path) { $type = KInflector::implode($identifier->path); } else { $type = $identifier->name; } } $parts = explode('.', $name); $name = 'on' . ucfirst(array_shift($parts)) . ucfirst($type) . KInflector::implode($parts); $event = new KEvent(clone $context); $event->setPublisher($context->caller); $this->_event_dispatcher->dispatchEvent($name, $event); return true; }
/** * Dispatches an event by dispatching arguments to all listeners that handle * the event and returning their return values. * * @param string The event name * @param object|array An array, a KConfig or a KEvent object * @return KEventDispatcher */ public function dispatchEvent($name, $event = array()) { $result = array(); //Make sure we have an event object if (!$event instanceof KEvent) { $event = new KEvent($event); } $event->setName($name)->setDispatcher($this); //Nofity the listeners if (isset($this->_listeners[$name])) { foreach ($this->_listeners[$name] as $listener) { $listener->{$name}($event); if (!$event->canPropagate()) { break; } } } return $this; }
/** * Publish an event by calling all listeners that have registered to receive it. * * @param string|KEventInterface $event The event name or a KEventInterface object * @param array|Traversable $attributes An associative array or a Traversable object * @param KObjectInterface $target The event target * @return null|KEventInterface Returns the event object. If the chain is not enabled will return NULL. */ public function publishEvent($event, $attributes = array(), $target = null) { if ($this->isEnabled()) { //Make sure we have an event object if (!$event instanceof KEventInterface) { $event = new KEvent($event, $attributes, $target); } //Notify the listeners $listeners = $this->getListeners($event->getName()); foreach ($listeners as $listener) { $start = microtime(true); call_user_func($listener, $event, $this); $this->__profiles[] = array('message' => $event->getName(), 'period' => microtime(true) - $start, 'time' => microtime(true), 'memory' => $this->getMemoryUsage(), 'target' => $target instanceof KObjectInterface ? $target->getIdentifier() : $target, 'listener' => $listener); if (!$event->canPropagate()) { break; } } return $event; } else { $this->getDelegate()->publishEvent($event, $attributes, $target); } return null; }
/** * Push the toolbar into the view * . * * @param KEvent A event object */ public function onBeforeControllerGet(KEvent $event) { KService::set('com:controller.toolbar', $this); $event->getPublisher()->getView()->toolbar = $this; }
/** * Publish an event by calling all listeners that have registered to receive it. * * @param string|KEventInterface $event The event name or a KEventInterface object * @param array|Traversable|KEventInterface $attributes An associative array, an object implementing the * KEventInterface or a Traversable object * @param mixed $target The event target * @throws InvalidArgumentException If the event is not a string or does not implement the KEventInterface * @return null|KEventInterface Returns the event object. If the chain is not enabled will return NULL. */ public function publishEvent($event, $attributes = array(), $target = null) { if ($this->isEnabled()) { if (!is_string($event) && !$event instanceof KEventInterface) { throw new InvalidArgumentException('The event must be a string or implement the KEventInterface, "' . gettype($event) . '" given.'); } //Make sure we have an event object if (!$event instanceof KEventInterface) { if ($attributes instanceof KEventInterface) { $name = $event; $event = $attributes; $event->setName($name); } else { $event = new KEvent($event, $attributes, $target); } } //Notify the listeners $listeners = $this->getListeners($event->getName()); foreach ($listeners as $listener) { call_user_func($listener, $event, $this); if (!$event->canPropagate()) { break; } } return $event; } return null; }
/** * Push the toolbar into the view * . * @param KEvent A event object */ public function onBeforeControllerGet(KEvent $event) { $event->getPublisher()->getView()->toolbar = $this; }