Prooph\ServiceBus\CommandBus::dispatch PHP Method

dispatch() public method

public dispatch ( mixed $command ) : void
$command mixed
return void
    public function dispatch($command)
    {
        $this->commandQueue[] = $command;
        if (!$this->isDispatching) {
            $this->isDispatching = true;
            try {
                while ($command = array_shift($this->commandQueue)) {
                    $this->processCommand($command);
                }
                $this->isDispatching = false;
            } catch (\Exception $e) {
                $this->isDispatching = false;
                throw CommandDispatchException::wrap($e, $this->commandQueue);
            }
        }
    }

Usage Example

 public function create($connection)
 {
     if (!array_key_exists('type', $connection)) {
         return $this->apiProblem(422, "No type given for the connection");
     }
     if (!array_key_exists('message_handler', $connection)) {
         return $this->apiProblem(422, "No message_handler given for the connection");
     }
     if (!array_key_exists('workflow_id', $connection)) {
         return $this->apiProblem(422, "No workflow_id given for the connection");
     }
     if ($connection['type'] == "start_connection") {
         if (!array_key_exists('start_message', $connection)) {
             return $this->apiProblem(422, "No start_message given for the connection");
         }
         $this->commandBus->dispatch(ScheduleFirstTasksForWorkflow::withData($connection['workflow_id'], $connection['start_message'], $connection['message_handler']));
         return $this->accepted();
     } elseif ($connection['type'] == "source_target_connection") {
         if (!array_key_exists('previous_task', $connection)) {
             return $this->apiProblem(422, "No previous_task given for the connection");
         }
         $this->commandBus->dispatch(ScheduleNextTasksForWorkflow::withData($connection['workflow_id'], $connection['previous_task'], $connection['message_handler']));
         return $this->accepted();
     } else {
         return $this->apiProblem(422, "Unknown connection type");
     }
 }
All Usage Examples Of Prooph\ServiceBus\CommandBus::dispatch