Exemplo n.º 1
0
 /**
  * Emits a signal.
  *
  * @param  object  $signal  \XPSPL\SIG
  *
  * @return  object  Event
  */
 public function emit(SIG $signal)
 {
     if (XPSPL_DEBUG) {
         logger(XPSPL_LOG)->debug(sprintf('%s emitted', $signal));
     }
     // Store the history of the signal
     if (false !== $this->_history) {
         $this->_history[] = [$signal, microtime()];
     }
     // Set child status
     if (count($this->_signal) > 1) {
         $signal->set_parent($this->current_signal());
     }
     // Check if signal is installed
     $memory = $this->find_signal_database($signal);
     if (null === $memory) {
         $memory = new \XPSPL\database\Processes();
     } else {
         if (XPSPL_DEBUG) {
             logger(XPSPL_LOG)->debug('Signal with no installed processes emitted');
         }
     }
     // Evaluate complex signals
     $evaluated = $this->evaluate_signals($signal);
     if (null !== $evaluated) {
         foreach ($evaluated as $_db) {
             $memory->merge($_db);
         }
     }
     // Execute if we have processes
     if ($memory->count() > 0) {
         // Set as currently executing signal
         $this->_signal[] = $signal;
         // Execute
         $this->_execute($signal, $memory);
         // Remove once finished
         array_pop($this->_signal);
     }
     return $signal;
 }
Exemplo n.º 2
0
 /**
  * Determine if the given database processes are exhausted.
  *
  * @param  object  $queue  \XPSPL\database\Processes
  *
  * @return  boolean
  */
 public function are_processes_exhausted(\XPSPL\database\Processes $database)
 {
     if ($database->count() === 0) {
         return true;
     }
     $database->reset();
     while ($database->valid()) {
         if ($database->current() instanceof \XPSPL\database\Processes) {
             if (!$this->are_processes_exhausted($database->current())) {
                 return false;
             }
         } elseif (!$database->current()->is_exhausted()) {
             return false;
         }
         $database->next();
     }
     return true;
 }