Example #1
0
 /**
  * Fires event.
  * @param int one event (e.g. Events::HYDRATE_BEFORE)
  * @param IEntity|NULL
  * @param array reference
  * @return Events $this
  * @see EventArguments
  */
 public function fireEvent($type, IEntity $entity = NULL, array &$arguments = array())
 {
     if (!isset(self::$instructions[$type])) {
         throw new InvalidArgumentException(array($this, 'fireEvent() $type', 'valid event type', $type));
     }
     $hasEntityEvent = self::$instructions[$type][2];
     if ($hasEntityEvent or $this->listeners[$type]) {
         $args = new EventArguments($type, $this->repository, $entity, $arguments);
         foreach ($this->listeners[$type] as $k => $event) {
             if ($event[0] === false) {
                 $this->handleLazy($event[1]);
                 $event = $this->listeners[$type][$k];
             }
             call_user_func($event[1], $args);
             $args->check();
             // srozumitelna chyba na ukor vykonu
         }
         $arguments = $args->getArguments();
     }
     if ($hasEntityEvent) {
         $more = NULL;
         if ($hasEntityEvent === 'onLoad') {
             $more = $args->data;
         } else {
             if ($hasEntityEvent === 'onPersist') {
                 $more = $args->id;
             }
         }
         $entity->fireEvent($hasEntityEvent, $this->repository, $more);
     }
     return $this;
 }