Example #1
0
 /**
  * @return array|callable[]
  */
 public function getListeners()
 {
     $listeners = $this->listeners;
     if ($this->panel) {
         $this->panel->inlineCallbacks($this->getName(), $listeners);
     } elseif (!$this->eventManager || !$this->eventManager->hasListeners($this->getName())) {
         return $listeners;
     }
     $name = $this->getName();
     $evm = $this->eventManager;
     $argsClass = $this->argsClass;
     $globalDispatch = function () use($name, $evm, $argsClass) {
         if ($argsClass === NULL) {
             $args = new EventArgsList(func_get_args());
         } else {
             $args = Nette\Reflection\ClassType::from($argsClass)->newInstanceArgs(func_get_args());
         }
         $evm->dispatchEvent($name, $args);
     };
     if ($this->globalDispatchFirst) {
         array_unshift($listeners, $globalDispatch);
     } else {
         $listeners[] = $globalDispatch;
     }
     return $listeners;
 }
Example #2
0
 /**
  * @param array|string $unsubscribe
  * @param Doctrine\Common\EventSubscriber|array $subscriber
  */
 public function removeEventListener($unsubscribe, $subscriber = NULL)
 {
     foreach ((array) $unsubscribe as $eventName) {
         if (array_key_exists($eventName, $this->listenerIds)) {
             $this->initializeListener($eventName);
         }
     }
     parent::removeEventListener($unsubscribe, $subscriber);
 }
Example #3
0
 private function initKdybyEvents()
 {
     static $events = [Events::EVENT_BEFORE_PERSIST, Events::EVENT_BEFORE_CREATE, Events::EVENT_BEFORE_UPDATE, Events::EVENT_BEFORE_DELETE, Events::EVENT_AFTER_PERSIST, Events::EVENT_AFTER_CREATE, Events::EVENT_AFTER_UPDATE, Events::EVENT_AFTER_DELETE];
     foreach ($events as $eventName) {
         $ns = get_called_class();
         $event = $this->evm->createEvent($ns . '::' . $eventName);
         $this->events->registerCallback($eventName, $event);
     }
 }
Example #4
0
 /**
  * @param User $user
  * @param callable $createBridge
  * @throws Exception
  * @return BadgeUserBridge
  */
 public function awardTo(User $user, callable $createBridge)
 {
     $badge = $this->orm->badges->getByKey($this->key);
     /** @var BadgeUserBridge $bridge */
     $bridge = $createBridge($badge, $user);
     $bridge->injectTranslator($badge->translator);
     $this->orm->badgeUserBridges->attach($bridge);
     $this->eventManager->dispatchEvent(EventList::BADGE_AWARDED, new EventArgsList([$bridge]));
     return $bridge;
 }
Example #5
0
 /**
  * @param array|string $unsubscribe
  * @param Doctrine\Common\EventSubscriber|array $subscriber
  */
 public function removeEventListener($unsubscribe, $subscriber = NULL)
 {
     if ($unsubscribe instanceof EventSubscriber) {
         list($unsubscribe, $subscriber) = $this->extractSubscriber($unsubscribe);
     }
     foreach ((array) $unsubscribe as $eventName) {
         if (array_key_exists($eventName, $this->listenerIds)) {
             $this->initializeListener($eventName);
         }
     }
     parent::removeEventListener($unsubscribe, $subscriber);
 }
 /**
  * {@inheritDoc}
  */
 public function createEvent($name, $defaults = [], $argsClass = NULL, $globalDispatchFirst = FALSE)
 {
     return $this->evm->createEvent($this->namespace . $name, $defaults, $argsClass, $globalDispatchFirst);
 }
 /**
  * {@inheritDoc}
  */
 public function createEvent($name, $defaults = array(), $argsClass = NULL)
 {
     return $this->evm->createEvent($this->namespace . $name, $defaults, $argsClass);
 }
 private function fireEvent($name)
 {
     if ($this->eventManager) {
         $this->eventManager->dispatchEvent($name);
     }
 }
Example #9
0
 /**
  * @param EventManager $evm
  */
 public function setEventManager(EventManager $evm)
 {
     $this->evm = $evm;
     $evm->setPanel($this);
 }
Example #10
0
 public function fireEvent($event, $args = [])
 {
     $this->eventManager->dispatchEvent(get_class($this) . '::' . $event, new Kdyby\Events\EventArgsList($args));
 }
Example #11
0
 public function hasListeners($eventName = null)
 {
     return $this->evm->hasListeners($eventName);
 }
 private function onRun(InputInterface $input, OutputInterface $output)
 {
     $this->eventManager->dispatchEvent(__METHOD__, new EventArgsList([$input, $output]));
 }
 public function startup()
 {
     parent::startup();
     $this->translator->setLanguage('cs');
     $this->eventManager->addEventSubscriber($this);
 }