protected function compositionDefault(
        $default,
        CompositionDefinition $composition,
        SchemaBuilder $builder
    ) {
        if (!is_array($default)) {
            if ($composition->getType() == DocumentEntity::MANY) {
                //Composition many must always defaults to array
                return [];
            }

            //Composite ONE must always defaults to null if no default value are specified
            return null;
        }

        //Nothing to do with value for composite many
        if ($composition->getType() == DocumentEntity::MANY) {
            return $default;
        }

        $embedded = $builder->getSchema($composition->getClass());
        if (!$embedded instanceof self) {
            //We can not normalize values handled by external schemas yet
            return $default;
        }

        if ($embedded->getClass() == $this->getClass()) {
            if (!empty($default)) {
                throw new SchemaException(
                    "Possible recursion issue in '{$this->getClass()}', model refers to itself (has default value)"
                );
            }

            //No recursions!
            return null;
        }

        return $embedded->packDefaults($builder, $default);
    }
protected function compositionDefault(
        $default,
        CompositionDefinition $composition,
        SchemaBuilder $builder
    ) {
        if (!is_array($default)) {
            if ($composition->getType() == DocumentEntity::MANY) {
                //Composition many must always defaults to array
                return [];
            }

            //Composite ONE must always defaults to null if no default value are specified
            return null;
        }

        //Nothing to do with value for composite many
        if ($composition->getType() == DocumentEntity::MANY) {
            return $default;
        }

        $embedded = $builder->getSchema($composition->getClass());
        if (!$embedded instanceof self) {
            //We can not normalize values handled by external schemas yet
            return $default;
        }

        if ($embedded->getClass() == $this->getClass()) {
            if (!empty($default)) {
                throw new SchemaException(
                    "Possible recursion issue in '{$this->getClass()}', model refers to itself (has default value)"
                );
            }

            //No recursions!
            return null;
        }

        return $embedded->packDefaults($builder, $default);
    }
protected function compositionDefault ( $ default , CompositionDefinition $ composition , SchemaBuilder $ builder ) { if ( ! is_array ( $ default ) ) { if ( $ composition -> getType ( ) == DocumentEntity :: MANY ) { //Composition many must always defaults to array return [ ] ; } //Composite ONE must always defaults to null if no default value are specified return null ; } //Nothing to do with value for composite many if ( $ composition -> getType ( ) == DocumentEntity :: MANY ) { return $ default ; } $ embedded = $ builder -> getSchema ( $ composition -> getClass ( ) ) ; if ( ! $ embedded instanceof self ) { //We can not normalize values handled by external schemas yet return $ default ; } if ( $ embedded -> getClass ( ) == $ this -> getClass ( ) ) { if ( ! empty ( $ default ) ) { throw new SchemaException ( "Possible recursion issue in '{$this->getClass()}', model refers to itself (has default value)" ) ; } //No recursions! return null ; } return $ embedded -> packDefaults ( $ builder , $ default ) ; }
Ensure default value for composite field,

@param mixed                 $default
@param CompositionDefinition $composition
@param SchemaBuilder         $builder

@return array

@throws SchemaException
Ensure default value for composite field