Esempio n. 1
0
 /**
  * call registered hooks
  *
  * This function can be called like:
  *  $m->call(new Am_Event_SubscriptionAdded())
  *  $m->call(new Event('myEventId', array('user' => $user)));
  *  or the same 
  *  $m->call('myEventId', array('user' => $user));
  *  or if no parameters necessary
  *  $m->call('myEventId');
  * 
  * @param string|Am_Event $hookOrEvent
  * @param Am_Event|arraynull $event
  * @return Am_Event
  */
 function call($hook, $event = null)
 {
     if ($event === null) {
         if (is_string($hook)) {
             $event = new Am_Event($hook);
         } elseif ($hook instanceof Am_Event) {
             $event = $hook;
             $hook = $event->getId();
         } else {
             throw new Am_Exception_InternalError("Unknown argument for " . __METHOD__);
         }
     } elseif (is_array($event)) {
         $event = new Am_Event($hook, $event);
     }
     $event->_setDi($this->di);
     foreach ($this->observers as $o) {
         // notify observers
         call_user_func($o, $event, $hook, $this);
     }
     if (!$this->disableAll && !array_key_exists($hook, $this->disabled) && array_key_exists($hook, $this->hooks) && count($this->hooks[$hook])) {
         $event->handle($this->hooks[$hook]);
     }
     return $event;
 }