Example #1
0
File: Signal.php Project: cwcw/cms
 /**
  * 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;
 }