Esempio n. 1
0
 public function getTaskByStateAndEvent(StateMachineInterface $state_machine, ProjectionInterface $resource, $event)
 {
     $workflow_subject = new WorkflowSubject($state_machine->getName(), $resource);
     $state_machine->execute($workflow_subject, $event);
     $workflow_context = $workflow_subject->getExecutionContext();
     if (!$workflow_context->hasParameter('task_action')) {
         throw new RuntimeError('Expected "task_action" parameter to be set after workflow execution.');
     }
     return $workflow_context->getParameter('task_action')->toArray();
 }
Esempio n. 2
0
 /**
  * Transition to the next workflow state (next state of the state machine based on the command paylaod).
  *
  * @param ProceedWorkflowCommand $workflow_command
  * @param StateMachineInterface $state_machine
  */
 public function proceedWorkflow(ProceedWorkflowCommand $workflow_command, StateMachineInterface $state_machine)
 {
     $this->guardCommandPreConditions($workflow_command);
     if ($workflow_command->getCurrentStateName() !== $this->getWorkflowState()) {
         throw new RuntimeError(sprintf('The AR\'s(%s) current state %s does not match the given command state %s.', $this, $this->getWorkflowState(), $workflow_command->getCurrentStateName()));
     }
     $workflow_subject = new WorkflowSubject($state_machine->getName(), $this);
     $state_machine->execute($workflow_subject, $workflow_command->getEventName());
     $workflow_data = ['workflow_state' => $workflow_subject->getCurrentStateName(), 'workflow_parameters' => $workflow_subject->getWorkflowParameters()];
     $proceeded_event = $this->processCommand($workflow_command, ['data' => $workflow_data]);
     if (!$proceeded_event instanceof WorkflowProceededEvent) {
         throw new RuntimeError(sprintf('Corrupt event type detected. Events that reflect workflow transitions must descend from %s.', WorkflowProceededEvent::CLASS));
     }
     $this->applyEvent($proceeded_event);
 }