XPSPL\database\Processes::merge PHP Method

merge() public method

The merged into database (self) takes precedence of the merged in database in FIFO.
public merge ( $array ) : void
return void
    public function merge($array)
    {
        // ....
        if (!$array instanceof Processes) {
            throw new \InvalidArgumentException(sprintf('Instanceof \\XPSPL\\database\\Processes required recieved %s', is_object($array) ? get_class($array) : gettype($array)));
        }
        foreach ($array as $_priority => $_process) {
            if ($_process instanceof Processes) {
                foreach ($_process as $_sub_process) {
                    $_sub_process->set_priority($_priority);
                    $this->install($_sub_process);
                }
            } else {
                if (XPSPL_DEBUG) {
                    logger(XPSPL_LOG)->debug(sprintf('%s merged', $_process));
                }
                $this->install($_process);
            }
        }
    }

Usage Example

コード例 #1
0
ファイル: processor.php プロジェクト: prggmr/xpspl
 /**
  * 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;
 }