Exemplo n.º 1
0
 /**
  * Process a workflow decision, sending the reason back to the workflow engine
  *
  * @param Decision $decision
  */
 public function processDecision(Decision $decision)
 {
     switch ($decision->getWorkflowResult()) {
         // Complete a workflow
         case WorkflowResult::COMPLETE():
             $class = 'RespondDecisionCompleteCommand';
             $event = new CompletingWorkflowEvent($this->getWorkflow(), $decision->getExecutionId(), $decision->getResult());
             $this->dispatch(Event::DECISION_COMPLETE, $event);
             $this->getWorkflow()->onWorkflowSuccess($event);
             $this->getWorkflow()->onWorkflowComplete($event);
             break;
             // Fail a workflow
         // Fail a workflow
         case WorkflowResult::FAIL():
             $class = 'RespondDecisionFailedCommand';
             $event = new FailingWorkflowEvent($this->getWorkflow(), $decision->getExecutionId(), $decision->getReason());
             $this->dispatch(Event::DECISION_FAIL, $event);
             $this->getWorkflow()->onWorkflowFailed($event);
             $this->getWorkflow()->onWorkflowComplete($event);
             break;
             // Send workflow commands
         // Send workflow commands
         case WorkflowResult::COMMAND():
             $class = 'RespondDecisionScheduleCommand';
             foreach ($decision->getScheduledTasks() as $task) {
                 $this->dispatch(Event::DECISION_SCHEDULE, new SchedulingTaskEvent($task));
             }
             break;
             // Unsupported response
         // Unsupported response
         default:
             throw new UnexpectedValueException("Unknown workflow result: " . $decision->getWorkflowResult()->key());
     }
     $this->runCommand($class, ['decision' => $decision]);
 }