Beispiel #1
0
 /**
  * Flush the listeners belonging to $groupName in the current php id
  *
  * @param string $groupName
  * @return void
  */
 protected function _flushByGroup($groupName)
 {
     $phpId = $this->_registry->get(SW_ENGINE_CURRENT_PHPID);
     if (null === $phpId) {
         return;
     }
     if (!isset($this->_list[$phpId])) {
         return;
     }
     foreach ($this->_list[$phpId] as $eventType => $listeners) {
         foreach ($listeners as $offset => $listener) {
             if ($listener->getGroup() === $groupName) {
                 if (isset($currentEventType) && $currentEventType !== $eventType) {
                     if (count($this->_list[$phpId][$currentEventType]) === 0) {
                         unset($this->_list[$phpId][$currentEventType]);
                     }
                 }
                 unset($this->_list[$phpId][$eventType][$offset]);
                 $this->_count--;
                 $currentEventType = $eventType;
             }
         }
     }
     if (isset($currentEventType)) {
         $this->_performListMaintenance($phpId, $currentEventType);
     }
     $logMessage = 'Flushed ALL event listeners belonging to group "%s" in the current phpId ("%d") in class "%s"';
     Streamwide_Engine_Logger::debug(sprintf($logMessage, $groupName, $phpId, $this->_class));
     $logMessage = 'The event listeners count for class "%s" is %d';
     Streamwide_Engine_Logger::debug(sprintf($logMessage, $this->_class, $this->_count));
 }
Beispiel #2
0
 /**
  * Retrieve the controller reference from the registry
  *
  * @return Streamwide_Engine_Controller
  * @throws Exception
  */
 public function getController()
 {
     $controller = $this->_registry->get(SW_ENGINE_CONTROLLER);
     if (null === $controller) {
         throw new Exception('Controller object not set in the registry');
     }
     return $controller;
 }
Beispiel #3
0
 /**
  * Resets the registry (used for testing purposes)
  *
  * @return void
  */
 public function reset()
 {
     $this->_registry = array();
     self::$_instance = null;
 }
Beispiel #4
0
 /**
  * Retrieve the next signal from the SW Engine's event queue
  *
  * @param array $options
  * @return Streamwide_Engine_Signal|boolean
  */
 public static function dequeue(array $options = null)
 {
     $registry = Streamwide_Engine_Registry::getInstance();
     // initialize options to their default values
     if (null === ($engineProxy = $registry->get(SW_ENGINE_PROXY))) {
         $engineProxy = new Streamwide_Engine_Proxy();
         $registry->set(SW_ENGINE_PROXY, $engineProxy);
     }
     $timeout = -1;
     $savePhpId = true;
     if (is_array($options)) {
         if (isset($options['timeout'])) {
             $timeout = (int) $options['timeout'];
         }
         if (isset($options['engineProxy']) && $options['engineProxy'] instanceof Streamwide_Engine_Proxy) {
             $engineProxy = $options['engineProxy'];
             $registry->set(SW_ENGINE_PROXY, $engineProxy);
         }
         if (isset($options['savePhpId'])) {
             $savePhpId = (bool) $options['savePhpId'];
         }
     }
     if (false === ($array = $engineProxy->nextEvent($timeout))) {
         return false;
     }
     $name = $array[self::SIG_NAME];
     $phpId = $array[self::SIG_PHPID];
     $remote = $array[self::SIG_REMOTE];
     $params = $array[self::SIG_PARAMS];
     if ($savePhpId) {
         $registry->set(SW_ENGINE_CURRENT_PHPID, $phpId);
     }
     $signal = new self($engineProxy);
     $signal->setName($name);
     $signal->setPhpId($phpId);
     $signal->setRemote($remote);
     $signal->setParams($params);
     return $signal;
 }
Beispiel #5
0
 /**
  * Set a logger to be used by this class
  *
  * @param Streamwide_Log $log
  * @param boolean $overwrite
  * @return void
  */
 public static function setLog(Streamwide_Log $log, $overwrite = true)
 {
     $self = self::_getInstance();
     if (null !== $self->_log && false === $overwrite) {
         return null;
     }
     if (defined('SW_ENGINE_LOG')) {
         $registry = Streamwide_Engine_Registry::getInstance();
         $registry->set(SW_ENGINE_LOG, $log);
     }
     $self->_log = $log;
 }