コード例 #1
0
 /**
  * Filters events that do not pass the contained filter.
  *
  * @param \Phergie\Irc\Event\EventInterface $event
  * @return boolean|null TRUE if the contained filter fails, FALSE if it passes,
  *         or NULL if it returns NULL.
  */
 public function filter(EventInterface $event)
 {
     $result = $this->filter->filter($event);
     if ($result === null) {
         return null;
     }
     return !$result;
 }
コード例 #2
0
 public function handleIrcReceived(UserEvent $event, EventQueue $queue)
 {
     $params = $event->getParams();
     $extractor = new \Twitter_Extractor($params['text']);
     $urls = $extractor->extractURLs();
     foreach ($urls as $url) {
         if ($this->filter !== null && $this->filter->filter(new UrlEvent($url, $event)) !== false) {
             continue;
         }
         $this->handleUrl($url, $event, $queue);
     }
 }
コード例 #3
0
 /**
  * Applies filters to events and forwards those that pass to contained
  * plugins.
  *
  * @param string $event Name of the intercepted event, used to forward
  *        the event to listeners
  * @param array $args Event arguments
  */
 public function handleEvent($event, array $args)
 {
     $logger = $this->getLogger();
     $eventObjects = array_filter($args, function ($arg) {
         return $arg instanceof EventInterface;
     });
     if (!$eventObjects) {
         $logger->info('Event emitted without EventInterface argument', array('event' => $event, 'args' => $args));
     } else {
         $eventObject = reset($eventObjects);
         if ($this->filter->filter($eventObject) === false) {
             $logger->info('Event did not pass filter, skipping', array('event' => $event, 'args' => $args));
             return;
         } else {
             $logger->info('Event passed filter, forwarding', array('event' => $event, 'args' => $args));
         }
     }
     $callbacks = $this->getEventHandlers($event);
     foreach ($callbacks as $callback) {
         $logger->info('Forwarding event to callback', array('event' => $event, 'args' => $args, 'callback' => $callback));
         call_user_func_array($callback, $args);
     }
 }