Entity default values.

@param SchemaBuilder $builder
@param array         $overwriteDefaults Set of default values to replace user defined values.

@return array

@throws SchemaException
541407
protected function packDefaults(SchemaBuilder $builder, array $overwriteDefaults = []): array
    {
        //Defined compositions
        $compositions = $this->getCompositions($builder);

        //User defined default values
        $userDefined = $overwriteDefaults + $this->getDefaults();

        //We need mutators to normalize default values
        $mutators = $this->getMutators();

        $defaults = [];
        foreach ($this->getFields() as $field => $type) {
            $default = is_array($type) ? [] : null;

            if (array_key_exists($field, $userDefined)) {
                //No merge to keep fields order intact
                $default = $userDefined[$field];
            }

            //Registering default values
            $defaults[$field] = $this->mutateValue(
                $builder,
                $compositions,
                $userDefined,
                $mutators,
                $field,
                $default
            );
        }

        return $defaults;
    }
289086
public function setDefault($default) {
        // Check, warn and auto-fix '' (empty) defaults for CHAR NOT NULL columns, changing them
        // to NULL so XMLDB will apply the proper default
        if ($this->type == XMLDB_TYPE_CHAR && $this->notnull && $default === '') {
            $this->errormsg = 'XMLDB has detected one CHAR NOT NULL column (' . $this->name . ") with '' (empty string) as DEFAULT value. This type of columns must have one meaningful DEFAULT declared or none (NULL). XMLDB have fixed it automatically changing it to none (NULL). The process will continue ok and proper defaults will be created accordingly with each DB requirements. Please fix it in source (XML and/or upgrade script) to avoid this message to be displayed.";
            $this->debug($this->errormsg);
            $default = null;
        }
        // Check, warn and autofix TEXT|BINARY columns having a default clause (only null is allowed)
        if (($this->type == XMLDB_TYPE_TEXT || $this->type == XMLDB_TYPE_BINARY) && $default !== null) {
            $this->errormsg = 'XMLDB has detected one TEXT/BINARY column (' . $this->name . ") with some DEFAULT defined. This type of columns cannot have any default value. Please fix it in source (XML and/or upgrade script) to avoid this message to be displayed.";
            $this->debug($this->errormsg);
            $default = null;
        }
        $this->default = $default;
    }
517907
public function getDefaults()
    {
        $this->initInternals();

        if (null === $this->defaults) {
            $this->defaults = $this->blueprintSchema->getDefaults();
        }

        return $this->defaults;
    }
808218
public function extend(Builder $builder)
    {
        foreach ($this->extensions as $extension) {
            $this->{"add{$extension}"}($builder);
        }

        $builder->onDelete(function(Builder $builder)
        {
            $column = $this->getDeletedAtColumn($builder);

            return $builder->update(array(
                $column => $builder->getModel()->freshTimestampString()
            ));
        });
    }
67519
protected function setDefaults($metaType, $mapping)
    {
        if (!is_array($mapping)) {
            $mapping = [];
        }

        $mapping = $this->setRootDefault('attributes', $mapping);
        $mapping = $this->setRootDefault('embeds', $mapping);
        $mapping = $this->setRootDefault('mixins', $mapping);
        if ('embed' === $metaType) {
            return $mapping;
        }

        $mapping = $this->setRootDefault('relationships', $mapping);
        if ('mixin' === $metaType) {
            return $mapping;
        }
        $this->setRootDefault('entity', $mapping);

        if (!isset($mapping['entity']['persistence']) || !is_array($mapping['entity']['persistence'])) {
            $mapping['entity']['persistence'] = [];
        }

        if (!isset($mapping['entity']['search']) || !is_array($mapping['entity']['search'])) {
            $mapping['entity']['search'] = [];
        }
        return $mapping;
    }
195801
public function read_default_value(Schema $field_schema, $default_value)
    {
        switch ($field_schema->type()) {
            case Schema::NULL_TYPE:
                return null;
            case Schema::BOOLEAN_TYPE:
                return $default_value;
            case Schema::INT_TYPE:
            case Schema::LONG_TYPE:
                return (int)$default_value;
            case Schema::FLOAT_TYPE:
            case Schema::DOUBLE_TYPE:
                return (float)$default_value;
            case Schema::STRING_TYPE:
            case Schema::BYTES_TYPE:
                return $default_value;
            case Schema::ARRAY_SCHEMA:
                $array = array();
                foreach ($default_value as $json_val) {
                    $val = $this->read_default_value($field_schema->items(), $json_val);
                    $array [] = $val;
                }
                return $array;
            case Schema::MAP_SCHEMA:
                $map = array();
                foreach ($default_value as $key => $json_val)
                    $map[$key] = $this->read_default_value($field_schema->values(),
                        $json_val);
                return $map;
            case Schema::UNION_SCHEMA:
                return $this->read_default_value($field_schema->schema_by_index(0),
                    $default_value);
            case Schema::ENUM_SCHEMA:
            case Schema::FIXED_SCHEMA:
                return $default_value;
            case Schema::RECORD_SCHEMA:
                $record = array();
                foreach ($field_schema->fields() as $field) {
                    $field_name = $field->name();
                    if (!$json_val = $default_value[$field_name])
                        $json_val = $field->default_value();

                    $record[$field_name] = $this->read_default_value($field->type(),
                        $json_val);
                }
                return $record;
            default:
                throw new Exception(sprintf('Unknown type: %s', $field_schema->type()));
        }
    }
573237
public function getSchemaDataDefaults()
    {
        $defaults = parent::getSchemaDataDefaults();
        $children = $this->getChildren();
        if ($children && $children->count()) {
            $childSchema = [];
            /** @var FormField $child */
            foreach ($children as $child) {
                $childSchema[] = $child->getSchemaData();
            }
            $defaults['children'] = $childSchema;
        }

        $defaults['data']['tag'] = $this->getTag();
        $defaults['data']['legend'] = $this->getLegend();

        // Scaffolded children will inherit this data
        $defaults['data']['inherited'] = [
            'data' => [
                'fieldholder' => 'small'
            ],
        ];

        return $defaults;
    }
75023
public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode    = $treeBuilder->root($this->alias);

        $rootNode
            ->children()
                ->booleanNode('use_doctrine_orm')->defaultFalse()->end()
                ->booleanNode('use_doctrine_odm')->defaultFalse()->end()
                ->booleanNode('use_propel')->defaultFalse()->end()
                ->booleanNode('overwrite_if_exists')->defaultFalse()->end()
                ->scalarNode('base_admin_template')
                    ->defaultValue("AdmingeneratorGeneratorBundle::base_admin.html.twig")
                ->end()
                ->scalarNode('dashboard_welcome_path')->defaultNull()->end()
                ->scalarNode('login_path')->defaultNull()->end()
                ->scalarNode('logout_path')->defaultNull()->end()
                ->scalarNode('exit_path')->defaultNull()->end()
                ->scalarNode('generator_cache')->defaultNull()->end()
                ->arrayNode('twig')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->booleanNode('use_form_resources')->defaultTrue()->end()
                        ->booleanNode('use_localized_date')->defaultFalse()->end()
                        ->scalarNode('date_format')->defaultValue('Y-m-d')->end()
                        ->scalarNode('datetime_format')->defaultValue('Y-m-d H:i:s')->end()
                        ->scalarNode('localized_date_format')->defaultValue('medium')->end()
                        ->scalarNode('localized_datetime_format')->defaultValue('medium')->end()
                        ->arrayNode('number_format')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->scalarNode('decimal')->defaultValue(0)->end()
                                ->scalarNode('decimal_point')->defaultValue('.')->end()
                                ->scalarNode('thousand_separator')->defaultValue(',')->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
                ->arrayNode('templates_dirs')
                    ->useAttributeAsKey('key')
                    ->prototype('scalar')->end()
                ->end()
                ->arrayNode('form_types')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('doctrine_orm')
                            ->addDefaultsIfNotSet()
                            ->children()
                                // datetime types
                                ->scalarNode('datetime')->defaultValue('datetime')->end()
                                ->scalarNode('vardatetime')->defaultValue('datetime')->end()
                                ->scalarNode('datetimetz')->defaultValue('datetime')->end()
                                ->scalarNode('date')->defaultValue('datetime')->end()
                                // time types
                                ->scalarNode('time')->defaultValue('time')->end()
                                // number types
                                ->scalarNode('decimal')->defaultValue('number')->end()
                                ->scalarNode('float')->defaultValue('number')->end()
                                // integer types
                                ->scalarNode('integer')->defaultValue('integer')->end()
                                ->scalarNode('bigint')->defaultValue('integer')->end()
                                ->scalarNode('smallint')->defaultValue('integer')->end()
                                // text types
                                ->scalarNode('string')->defaultValue('text')->end()
                                // textarea types
                                ->scalarNode('text')->defaultValue('textarea')->end()
                                // association types
                                ->scalarNode('entity')->defaultValue('entity')->end()
                                ->scalarNode('collection')->defaultValue('collection')->end()
                                // array types
                                ->scalarNode('array')->defaultValue('collection')->end()
                                // boolean types
                                ->scalarNode('boolean')->defaultValue('checkbox')->end()
                            ->end()
                        ->end()
                        ->arrayNode('doctrine_odm')
                            ->addDefaultsIfNotSet()
                            ->children()
                                // datetime types
                                ->scalarNode('datetime')->defaultValue('datetime')->end()
                                ->scalarNode('timestamp')->defaultValue('datetime')->end()
                                ->scalarNode('vardatetime')->defaultValue('datetime')->end()
                                ->scalarNode('datetimetz')->defaultValue('datetime')->end()
                                ->scalarNode('date')->defaultValue('datetime')->end()
                                // time types
                                ->scalarNode('time')->defaultValue('time')->end()
                                // number types
                                ->scalarNode('decimal')->defaultValue('number')->end()
                                ->scalarNode('float')->defaultValue('number')->end()
                                // integer types
                                ->scalarNode('int')->defaultValue('integer')->end()
                                ->scalarNode('integer')->defaultValue('integer')->end()
                                ->scalarNode('int_id')->defaultValue('integer')->end()
                                ->scalarNode('bigint')->defaultValue('integer')->end()
                                ->scalarNode('smallint')->defaultValue('integer')->end()
                                // text types
                                ->scalarNode('id')->defaultValue('text')->end()
                                ->scalarNode('custom_id')->defaultValue('text')->end()
                                ->scalarNode('string')->defaultValue('text')->end()
                                // textarea types
                                ->scalarNode('text')->defaultValue('textarea')->end()
                                // association types
                                ->scalarNode('document')->defaultValue('document')->end()
                                ->scalarNode('collection')->defaultValue('collection')->end()
                                // hash types
                                ->scalarNode('hash')->defaultValue('collection')->end()
                                // boolean types
                                ->scalarNode('boolean')->defaultValue('checkbox')->end()
                            ->end()
                        ->end()
                        ->arrayNode('propel')
                            ->addDefaultsIfNotSet()
                            ->children()
                                // datetime types
                                ->scalarNode('TIMESTAMP')->defaultValue('datetime')->end()
                                ->scalarNode('BU_TIMESTAMP')->defaultValue('datetime')->end()
                                // date types
                                ->scalarNode('DATE')->defaultValue('date')->end()
                                ->scalarNode('BU_DATE')->defaultValue('date')->end()
                                // time types
                                ->scalarNode('TIME')->defaultValue('time')->end()
                                // number types
                                ->scalarNode('FLOAT')->defaultValue('number')->end()
                                ->scalarNode('REAL')->defaultValue('number')->end()
                                ->scalarNode('DOUBLE')->defaultValue('number')->end()
                                ->scalarNode('DECIMAL')->defaultValue('number')->end()
                                // integer types
                                ->scalarNode('TINYINT')->defaultValue('integer')->end()
                                ->scalarNode('SMALLINT')->defaultValue('integer')->end()
                                ->scalarNode('INTEGER')->defaultValue('integer')->end()
                                ->scalarNode('BIGINT')->defaultValue('integer')->end()
                                ->scalarNode('NUMERIC')->defaultValue('integer')->end()
                                // text types
                                ->scalarNode('CHAR')->defaultValue('text')->end()
                                ->scalarNode('VARCHAR')->defaultValue('text')->end()
                                // textarea types
                                ->scalarNode('LONGVARCHAR')->defaultValue('textarea')->end()
                                ->scalarNode('BLOB')->defaultValue('textarea')->end()
                                ->scalarNode('CLOB')->defaultValue('textarea')->end()
                                ->scalarNode('CLOB_EMU')->defaultValue('textarea')->end()
                                // association types
                                ->scalarNode('model')->defaultValue('model')->end()
                                ->scalarNode('collection')->defaultValue('collection')->end()
                                // array types
                                ->scalarNode('PHP_ARRAY')->defaultValue('collection')->end()
                                // choice types
                                ->scalarNode('ENUM')->defaultValue('choice')->end()
                                // boolean types
                                ->scalarNode('BOOLEAN')->defaultValue('checkbox')->end()
                                ->scalarNode('BOOLEAN_EMU')->defaultValue('checkbox')->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
                ->arrayNode('filter_types')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('doctrine_orm')
                            ->addDefaultsIfNotSet()
                            ->children()
                                // datetime types
                                ->scalarNode('datetime')->end()
                                ->scalarNode('vardatetime')->end()
                                ->scalarNode('datetimetz')->end()
                                ->scalarNode('date')->end()
                                // time types
                                ->scalarNode('time')->end()
                                // number types
                                ->scalarNode('decimal')->end()
                                ->scalarNode('float')->end()
                                // integer types
                                ->scalarNode('integer')->end()
                                ->scalarNode('bigint')->end()
                                ->scalarNode('smallint')->end()
                                // text types
                                ->scalarNode('string')->end()
                                // textarea types
                                ->scalarNode('text')->defaultValue('text')->end()
                                // association types
                                ->scalarNode('entity')->end()
                                ->scalarNode('collection')->defaultValue('entity')->end()
                                // array types
                                ->scalarNode('array')->end()
                                // boolean types
                                ->scalarNode('boolean')->defaultValue('choice')->end()
                            ->end()
                        ->end()
                        ->arrayNode('doctrine_odm')
                            ->addDefaultsIfNotSet()
                            ->children()
                                // datetime types
                                ->scalarNode('datetime')->end()
                                ->scalarNode('timestamp')->end()
                                ->scalarNode('vardatetime')->end()
                                ->scalarNode('datetimetz')->end()
                                ->scalarNode('date')->end()
                                // time types
                                ->scalarNode('time')->end()
                                // number types
                                ->scalarNode('decimal')->end()
                                ->scalarNode('float')->end()
                                // integer types
                                ->scalarNode('int')->end()
                                ->scalarNode('integer')->end()
                                ->scalarNode('int_id')->end()
                                ->scalarNode('bigint')->end()
                                ->scalarNode('smallint')->end()
                                // text types
                                ->scalarNode('id')->end()
                                ->scalarNode('custom_id')->end()
                                ->scalarNode('string')->end()
                                // textarea types
                                ->scalarNode('text')->defaultValue('text')->end()
                                // association types
                                ->scalarNode('document')->end()
                                ->scalarNode('collection')->defaultValue('document')->end()
                                // hash types
                                ->scalarNode('hash')->defaultValue('text')->end()
                                // boolean types
                                ->scalarNode('boolean')->defaultValue('choice')->end()
                            ->end()
                        ->end()
                        ->arrayNode('propel')
                            ->addDefaultsIfNotSet()
                            ->children()
                                // datetime types
                                ->scalarNode('TIMESTAMP')->end()
                                ->scalarNode('BU_TIMESTAMP')->end()
                                // date types
                                ->scalarNode('DATE')->end()
                                ->scalarNode('BU_DATE')->end()
                                // time types
                                ->scalarNode('TIME')->end()
                                // number types
                                ->scalarNode('FLOAT')->end()
                                ->scalarNode('REAL')->end()
                                ->scalarNode('DOUBLE')->end()
                                ->scalarNode('DECIMAL')->end()
                                // integer types
                                ->scalarNode('TINYINT')->end()
                                ->scalarNode('SMALLINT')->end()
                                ->scalarNode('INTEGER')->end()
                                ->scalarNode('BIGINT')->end()
                                ->scalarNode('NUMERIC')->end()
                                // text types
                                ->scalarNode('CHAR')->end()
                                ->scalarNode('VARCHAR')->end()
                                // textarea types
                                ->scalarNode('LONGVARCHAR')->defaultValue('text')->end()
                                ->scalarNode('BLOB')->defaultValue('text')->end()
                                ->scalarNode('CLOB')->defaultValue('text')->end()
                                ->scalarNode('CLOB_EMU')->defaultValue('text')->end()
                                // association types
                                ->scalarNode('model')->end()
                                ->scalarNode('collection')->defaultValue('model')->end()
                                // array types
                                ->scalarNode('PHP_ARRAY')->defaultValue('choice')->end()
                                // choice types
                                ->scalarNode('ENUM')->end()
                                // boolean types
                                ->scalarNode('BOOLEAN')->defaultValue('choice')->end()
                                ->scalarNode('BOOLEAN_EMU')->defaultValue('choice')->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
                ->append($this->getStylesheetNode())
                ->append($this->getJavascriptsNode())
            ->end();

        return $treeBuilder;
    }
289710
protected function setDefaultValues($entity)
    {
        $entityClass = ClassUtils::getClass($entity);

        $meta = $this->extendedMetadataFactory->getExtendedMetadata($entityClass);

        if (!isset($meta['defaultValues']) || empty($meta['defaultValues'])) {
            return;
        }

        $defaultValuesMap = $meta['defaultValues'];
        $this->filterDefaultValuesMap($defaultValuesMap, $entity, $entityClass);

        if (empty($defaultValuesMap)) {
            return;
        }

        $sourcePropertyValues = $this->getSourcePropertyValues(
            array_unique(array_values($defaultValuesMap)),
            $entity,
            $entityClass
        );

        $recomputeChangeSet = false;

        foreach ($defaultValuesMap as $targetProperty => $sourcePropertyPath) {
            if (null === $sourcePropertyValues[$sourcePropertyPath]) {
                continue;
            }
            if (!$this->propertyAccessor->isWritable($entity, $targetProperty)) {
                throw new DefaultValueException(sprintf('Property "%s::$%s" is not writable.', $entityClass, $targetProperty));
            }

            $this->propertyAccessor->setValue($entity, $targetProperty, $sourcePropertyValues[$sourcePropertyPath]);

            $recomputeChangeSet = true;
        }
        if ($recomputeChangeSet) {
            $this->recomputeChangeSet($entity);
        }
    }
1161391
public function getSchema(): ?Builder
    {
        if (!$this->hasSchema()) {
            $this->setSchema($this->getDefaultSchema());
        }
        return $this->schema;
    }
1142743
public function getColumnDefaultValues ($table_name, $forced_obtain = false) {
		if ($forced_obtain || !Arrays::KeyExists($this->_columnDefaultValues, $table_name)) {
			$this->_updateColumnDefaultValues($table_name);
		}
		return $this->_columnDefaultValues[$table_name];
	}
594067
public static function GetColumnDefaultValues ($forced_obtain = false, $options = []) {
		$options += $options + static::GetDefaultOptions();
		return DBI::GetColumnDefaultValues($options, static::GetName(), $forced_obtain);
	}
887371
protected function _getDefault($field) {
		$default = null;
		$schema = $this->_table->getSchema()->getColumn($field);

		if ($schema && isset($schema['default'])) {
			$default = $schema['default'];
		}
		if ($this->_config['defaultValue'] !== null) {
			$default = $this->_config['defaultValue'];
		}

		return $default;
	}
1297584
public function setDefaultBuilder($name)
    {
        if (!$this->hasBuilder($name)) {
            throw new FoundationException(
                sprintf(
                    "No such builder '%s'.",
                    $name
                )
            );
        }

        $this->default = $name;

        return $this;
    }
1131553
protected function verifyOuter(SchemaBuilder $builder, AbstractColumn $column)
    {
        foreach ($this->findTargets($builder) as $schema) {
            $outerTable = $builder->requestTable($schema->getTable(), $schema->getDatabase());

            if (!$outerTable->hasColumn($column->getName())) {
                //Column is missing
                throw new RelationSchemaException(
                    "Unable to build morphed relation, outer key '{$column->getName()}' "
                    . "is missing in '{$outerTable->getName()}'"
                );
            }

            if ($outerTable->column($column->getName())->phpType() != $column->phpType()) {
                //Inconsistent type
                throw new RelationSchemaException(
                    "Unable to build morphed relation, outer key '{$column->getName()}' "
                    . "has different type in '{$outerTable->getName()}'"
                );
            }
        }
    }
50626
protected function prepareDefaultValues(
        Site $site,
        array $defaultSiteSettings,
        string $createdByUserId,
        string $createdReason
    ) {
        $defaults = $this->getDefaultSiteValues(
            $defaultSiteSettings,
            $createdByUserId,
            $createdReason
        );

        foreach ($defaults as $key => $value) {
            $getMethod = 'get' . ucfirst($key);
            $setMethod = 'set' . ucfirst($key);

            $currentValue = $site->$getMethod();

            if (empty($currentValue)) {
                $site->$setMethod($value);
            }
        }

        return $site;
    }
183641
public function extractDefault(ColumnSchema $field, $defaultValue)
    {
        if (strncmp($field->dbType, 'bit', 3) === 0) {
            $field->defaultValue = bindec(trim($defaultValue, 'b\''));
        } else {
            parent::extractDefault($field, $defaultValue);
        }
    }