/** * Create the data used to initialize a new aggregate-root. * * @param CreateAggregateRootCommand $create_command * @param StateMachineInterface $state_machine * * @return array */ protected function createInitialData(CreateAggregateRootCommand $create_command, StateMachineInterface $state_machine) { $type = $this->getType(); $type_prefix = $type->getPrefix(); $create_data = $create_command->getValues(); $create_data[self::OBJECT_TYPE] = $type_prefix; $value_or_default = function ($key, $default) use($create_data) { return isset($create_data[$key]) ? $create_data[$key] : $default; }; $uuid = $value_or_default('uuid', $type->getAttribute('uuid')->getDefaultValue()); $language = $value_or_default('language', $type->getAttribute('language')->getDefaultValue()); $version = $value_or_default('version', 1); $identifier = sprintf('%s-%s-%s-%s', $type_prefix, $uuid, $language, $version); $default_attributes = $type->getDefaultAttributes(); $non_default_attributes = $type->getAttributes()->filter(function (AttributeInterface $attribute) use($default_attributes) { return !$attribute instanceof EmbeddedEntityListAttribute && !array_key_exists($attribute->getName(), $default_attributes); }); $default_values = []; foreach ($non_default_attributes as $attribute_name => $attribute) { if (!$attribute->createValueHolder(true)->isNull()) { $default_values[$attribute_name] = $attribute->getDefaultValue(); } } return array_merge($default_values, $create_data, ['identifier' => $identifier, 'uuid' => $uuid, 'language' => $language, 'version' => $version, 'workflow_state' => $state_machine->getInitialState()->getName(), 'workflow_parameters' => []]); }
/** * Creates an array of dot-graph edges that connect the (state)nodes of the dot-graph. * * @param StateMachineInterface $state_machine * * @return array An array of strings, that represent the particular dot-graph edges. */ protected function getEdges(StateMachineInterface $state_machine) { $edges = []; foreach ($state_machine->getTransitions() as $state_name => $state_transitions) { foreach ($state_transitions as $event_name => $transitions) { foreach ($transitions as $transition) { $edges[] = $this->createEdge($transition, $state_name, $event_name); } } } $state_name = $state_machine->getInitialState()->getName(); $edges[] = sprintf('0 -> %s [color="%s"]', $this->node_id_map[$state_name], $this->getStyle('edge.colors.default', self::EDGE_DEFAULT_COLOR)); return $edges; }