protected function getPayloadIdentifier(ProcessStateInterface $process_state) { $identifier_path = $this->options->get('identifier_payload_path', false); $jmes_path_runtime = new AstRuntime(); $identifier = $jmes_path_runtime($identifier_path, $process_state->getPayload()); if (!$identifier) { throw new RuntimeError('Unable to resolve required "identifier" from payload-path:' . $identifier_path . ' within ' . $process_state->getExecutionContext()->getStateMachineName()); } return $identifier; }
protected function getStateMachineState(ProcessStateInterface $process_state) { $state = null; if ($state_name = $process_state->getStateName()) { $state = $this->state_machine->getState($state_name); if (!$state) { throw new RuntimeError('Process state can not be resolved: ' . $state_name); } } return $state; }
protected function createCommands(ProcessStateInterface $process_state) { $commands = []; $payload = $process_state->getPayload(); foreach ($payload['affected_entities'] as $affected_entity) { $origin_state = $payload['origin_state']; $type_prefix = $affected_entity['type_prefix']; // @todo handling for transition based on type as well as state $transitions = $this->transition_map->get($type_prefix); if (isset($transitions[$origin_state])) { $command_class = $transitions['command']; $aggregate_root_type = $this->aggregate_root_type_map->getItem($type_prefix); $commands[] = new $command_class(['aggregate_root_type' => get_class($aggregate_root_type), 'aggregate_root_identifier' => $affected_entity['identifier'], 'known_revision' => $affected_entity['revision'], 'current_state_name' => $affected_entity['state'], 'event_name' => $transitions[$origin_state]]); } } return $commands; }
protected function runProcess(ProcessStateInterface $process_state, EventInterface $event = null) { $process = $this->process_map->getItem($process_state->getProcessName()); if (!$process->hasFinished($process_state)) { $commands = $process->proceed($process_state, $event); $this->persistProcessState($process_state); $this->stack_depth++; if ($commands instanceof CommandList && !$commands->isEmpty()) { foreach ($commands as $command) { $this->command_bus->post($command); } } $this->stack_depth--; } else { throw new RuntimeError('The given process has already completed and may not be run again.'); } if ($this->hasCompleted($process_state) && $this->stack_depth === 0) { $resulting_process_state = $this->purgeProcessState($process_state->getUuid()); } else { $resulting_process_state = $this->readProcessState($process_state->getUuid()); } return $resulting_process_state; }
protected function getProjection(ProcessStateInterface $process_state) { return $process_state->getExecutionContext()->getParameter($this->options->get('projection_key')); }