src/Model/Aggregate/AggregateRoot.php
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' => []
            ]
        );
    }
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' => []
            ]
        );
    }
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' => [ ] ] ) ; }
Create the data used to initialize a new aggregate-root.

@param CreateAggregateRootCommand $create_command
@param StateMachineInterface $state_machine

@return array
Create the data used to initialize a new aggregate - root .