private function getOptionsResolverFunctionDeclaration()
    {

        // get required properties
        $required = [];
        $optional = [];
        $allowedValues = [];

        // optional
        foreach( $this->entity->dataTypes as $name => $dataType ) {

            // is required
            if( !$dataType->getDefault() and !$dataType->isNullable() ) {
                $required[] = $name;
            } else {
                $optional[] = $name;
            }

            // set allowed values (currently only works for enums)
            if( $dataType->isEnum($enumName) ) {
                // At the moment this is bugged in Symfony.Don't think it is of vital importance. Ignoring for now.
                # $allowedValues[$name] = $enumName;
            }

        }

        // allowed values declaration
        $allowedValuesPhp = '';
        if( $allowedValues ) {
            $allowedValuesPhp = "\n\$resolver->setAllowedValues(\n    array(\n";
            // at the moment this enum supported only
            foreach( $allowedValues as $column => $enumName ) {
                $allowedValuesPhp .= sprintf(
                    '        %s => Enum::getValues(%s),%s',
                    Php::varExport( $column ),
                    Php::varExport( $enumName ),
                    "\n"
                );
            }
            $allowedValuesPhp .= "    )\n);";
            $allowedValuesPhp = new Format( $allowedValuesPhp );
        }

        // require block
        $requiredPhp = new Format();
        if( $required ) {
            $requiredPhp = "\n\$resolver->setRequired(\n" . (new Format(Php::varExport( $required )))->indent(4) . "\n);";
            $requiredPhp = new Format($requiredPhp);
            $requiredPhp->indent(24);
        }

        // optional
        $optionalPhp = new Format();
        if( $optional ) {
            $optionalPhp = "\n\$resolver->setOptional(\n" . (new Format(Php::varExport( $optional )))->indent(4) . "\n);";
            $optionalPhp = new Format($optionalPhp);
            $optionalPhp->indent(24);
        }

        $this->class->addUses('Symfony\Component\OptionsResolver\OptionsResolver');
        $this->class->classComponents[] = new FunctionDeclaration(
            'resolverGet',
            new Sformatf( <<<'PHP'
                /**
                 * Resolver getter. Singleton
                 * @return Symfony\Component\Options\Resolver
                 */
                public function resolverGet()
                {
                    // do we already have a resolver instance
                    if( !$this->resolver ) {

                        $resolver = new OptionsResolver();%s%s%s
                        $this->resolver = $resolver;

                    }
                    return $this->resolver;
                }
PHP
                , $requiredPhp,
                $optionalPhp,
                $allowedValuesPhp
            )
        );

        $this->class->classComponents[] = new VariableDeclaration(
            'resolver',
            new SFormatf( <<<'PHP'
                /**
                 * Options Resolver
                 * @var array
                 */
                private $resolver;
PHP
            )
        );

    }
private function getOptionsResolverFunctionDeclaration()
    {

        // get required properties
        $required = [];
        $optional = [];
        $allowedValues = [];

        // optional
        foreach( $this->entity->dataTypes as $name => $dataType ) {

            // is required
            if( !$dataType->getDefault() and !$dataType->isNullable() ) {
                $required[] = $name;
            } else {
                $optional[] = $name;
            }

            // set allowed values (currently only works for enums)
            if( $dataType->isEnum($enumName) ) {
                // At the moment this is bugged in Symfony.Don't think it is of vital importance. Ignoring for now.
                # $allowedValues[$name] = $enumName;
            }

        }

        // allowed values declaration
        $allowedValuesPhp = '';
        if( $allowedValues ) {
            $allowedValuesPhp = "\n\$resolver->setAllowedValues(\n    array(\n";
            // at the moment this enum supported only
            foreach( $allowedValues as $column => $enumName ) {
                $allowedValuesPhp .= sprintf(
                    '        %s => Enum::getValues(%s),%s',
                    Php::varExport( $column ),
                    Php::varExport( $enumName ),
                    "\n"
                );
            }
            $allowedValuesPhp .= "    )\n);";
            $allowedValuesPhp = new Format( $allowedValuesPhp );
        }

        // require block
        $requiredPhp = new Format();
        if( $required ) {
            $requiredPhp = "\n\$resolver->setRequired(\n" . (new Format(Php::varExport( $required )))->indent(4) . "\n);";
            $requiredPhp = new Format($requiredPhp);
            $requiredPhp->indent(24);
        }

        // optional
        $optionalPhp = new Format();
        if( $optional ) {
            $optionalPhp = "\n\$resolver->setOptional(\n" . (new Format(Php::varExport( $optional )))->indent(4) . "\n);";
            $optionalPhp = new Format($optionalPhp);
            $optionalPhp->indent(24);
        }

        $this->class->addUses('Symfony\Component\OptionsResolver\OptionsResolver');
        $this->class->classComponents[] = new FunctionDeclaration(
            'resolverGet',
            new Sformatf( <<<'PHP'
                /**
                 * Resolver getter. Singleton
                 * @return Symfony\Component\Options\Resolver
                 */
                public function resolverGet()
                {
                    // do we already have a resolver instance
                    if( !$this->resolver ) {

                        $resolver = new OptionsResolver();%s%s%s
                        $this->resolver = $resolver;

                    }
                    return $this->resolver;
                }
PHP
                , $requiredPhp,
                $optionalPhp,
                $allowedValuesPhp
            )
        );

        $this->class->classComponents[] = new VariableDeclaration(
            'resolver',
            new SFormatf( <<<'PHP'
                /**
                 * Options Resolver
                 * @var array
                 */
                private $resolver;
PHP
            )
        );

    }
private function getOptionsResolverFunctionDeclaration ( ) { // get required properties $ required = [ ] ; $ optional = [ ] ; $ allowedValues = [ ] ; // optional foreach ( $ this -> entity -> dataTypes as $ name => $ dataType ) { // is required if ( ! $ dataType -> getDefault ( ) and ! $ dataType -> isNullable ( ) ) { $ required [ ] = $ name ; } else { $ optional [ ] = $ name ; } // set allowed values (currently only works for enums) if ( $ dataType -> isEnum ( $ enumName ) ) { // At the moment this is bugged in Symfony.Don't think it is of vital importance. Ignoring for now. # $allowedValues[$name] = $enumName; } } // allowed values declaration $ allowedValuesPhp = '' ; if ( $ allowedValues ) { $ allowedValuesPhp = "\n\$resolver->setAllowedValues(\n    array(\n" ; // at the moment this enum supported only foreach ( $ allowedValues as $ column => $ enumName ) { $ allowedValuesPhp .= sprintf ( '        %s => Enum::getValues(%s),%s' , Php :: varExport ( $ column ) , Php :: varExport ( $ enumName ) , "\n" ) ; } $ allowedValuesPhp .= "    )\n);" ; $ allowedValuesPhp = new Format ( $ allowedValuesPhp ) ; } // require block $ requiredPhp = new Format ( ) ; if ( $ required ) { $ requiredPhp = "\n\$resolver->setRequired(\n" . ( new Format ( Php :: varExport ( $ required ) ) ) -> indent ( 4 ) . "\n);" ; $ requiredPhp = new Format ( $ requiredPhp ) ; $ requiredPhp -> indent ( 24 ) ; } // optional $ optionalPhp = new Format ( ) ; if ( $ optional ) { $ optionalPhp = "\n\$resolver->setOptional(\n" . ( new Format ( Php :: varExport ( $ optional ) ) ) -> indent ( 4 ) . "\n);" ; $ optionalPhp = new Format ( $ optionalPhp ) ; $ optionalPhp -> indent ( 24 ) ; } $ this -> class -> addUses ( 'Symfony\Component\OptionsResolver\OptionsResolver' ) ; $ this -> class -> classComponents [ ] = new FunctionDeclaration ( 'resolverGet' , new Sformatf (  <<<'PHP'
                /**
                 * Resolver getter. Singleton
                 * @return Symfony\Component\Options\Resolver
                 */
                public function resolverGet()
                {
                    // do we already have a resolver instance
                    if( !$this->resolver ) {

                        $resolver = new OptionsResolver();%s%s%s
                        $this->resolver = $resolver;

                    }
                    return $this->resolver;
                }
PHP , $ requiredPhp , $ optionalPhp , $ allowedValuesPhp ) ) ; $ this -> class -> classComponents [ ] = new VariableDeclaration ( 'resolver' , new SFormatf (  <<<'PHP'
                /**
                 * Options Resolver
                 * @var array
                 */
                private $resolver;
PHP ) ) ; }
Generate a get Options Resolver component for the enity
Generate a get Options Resolver component for the enity