src/RocknRoot/StrayFw/Database/Postgres/Schema.php
private function generateEnum(string $enumName, array $enumDefinition)
    {
        $definition = $this->getDefinition();
        $consts = null;

        $enumRealName = null;
        if (isset($enumDefinition['name']) === true) {
            $enumRealName = $enumDefinition['name'];
        } else {
            $enumRealName = Helper::codifyName($this->mapping) . '_' . Helper::codifyName($enumName);
        }

        if (isset($enumDefinition['values']) === false) {
            throw new InvalidSchemaDefinition('enum "' . $enumName . '" has no value');
        }
        foreach ($enumDefinition['values'] as $valueName => $valueAlias) {
            $valueRealName = null;
            if (is_string($valueName) === true) {
                $valueRealName = $valueName;
            } else {
                $valueRealName = Helper::codifyName($enumName) . '_' . Helper::codifyName($valueAlias);
            }
            $consts .= '    const VALUE_' . strtoupper(Helper::codifyName($valueAlias)) . ' = \'' . $enumRealName . '.' . $valueRealName . "';\n";
        }

        $mapping = Mapping::get($this->mapping);

        $path = rtrim($mapping['config']['models']['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        $path .= 'Base' . DIRECTORY_SEPARATOR . ucfirst($enumName) . '.php';
        $file = fopen($path, 'w+');
        if ($file === false) {
            throw new FileNotWritable('can\'t open "' . $path . '" with write permission');
        }
        $path .= 'Base' . DIRECTORY_SEPARATOR . ucfirst($enumName) . '.php';
        $content = "<?php\n\nnamespace " . ltrim(rtrim($mapping['config']['models']['namespace'], '\\'), '\\') . "\\Base;\n\nuse RocknRoot\StrayFw\Database\Provider\Enum;\n";
        $content .= "\nclass " . ucfirst($enumName) . " extends Enum\n{\n";
        $content .= "    public function getDatabaseName() : string\n    {\n        return '" . $mapping['config']['database'] . "';\n    }\n\n";
        $content .= "    public function getTableName() : string\n    {\n        return '" . $enumRealName . "';\n    }\n\n";
        $content .= $consts . "\n}";
        if (fwrite($file, $content) === false) {
            throw new FileNotWritable('can\'t write in "' . $path . '"');
        }
        fclose($file);

        $path = rtrim($mapping['config']['models']['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        $path .= ucfirst($enumName) . '.php';
        if (file_exists($path) === false) {
            $file = fopen($path, 'w+');
            if ($file === false) {
                throw new FileNotWritable('can\'t open "' . $path . '" with write permission');
            }
            $content = "<?php\n\nnamespace " . ltrim(rtrim($mapping['config']['models']['namespace'], '\\'), '\\') . ";\n\nuse " . rtrim($mapping['config']['models']['namespace'], '\\') . "\\Base\\" . ucfirst($enumName) . " as BaseEnum;\n\nclass " . ucfirst($enumName) . " extends BaseEnum\n{\n}";
            if (fwrite($file, $content) === false) {
                throw new FileNotWritable('can\'t write in "' . $path . '"');
            }
        }

        echo $enumName . ' - Done' . PHP_EOL;
    }
private function generateEnum(string $enumName, array $enumDefinition)
    {
        $definition = $this->getDefinition();
        $consts = null;

        $enumRealName = null;
        if (isset($enumDefinition['name']) === true) {
            $enumRealName = $enumDefinition['name'];
        } else {
            $enumRealName = Helper::codifyName($this->mapping) . '_' . Helper::codifyName($enumName);
        }

        if (isset($enumDefinition['values']) === false) {
            throw new InvalidSchemaDefinition('enum "' . $enumName . '" has no value');
        }
        foreach ($enumDefinition['values'] as $valueName => $valueAlias) {
            $valueRealName = null;
            if (is_string($valueName) === true) {
                $valueRealName = $valueName;
            } else {
                $valueRealName = Helper::codifyName($enumName) . '_' . Helper::codifyName($valueAlias);
            }
            $consts .= '    const VALUE_' . strtoupper(Helper::codifyName($valueAlias)) . ' = \'' . $enumRealName . '.' . $valueRealName . "';\n";
        }

        $mapping = Mapping::get($this->mapping);

        $path = rtrim($mapping['config']['models']['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        $path .= 'Base' . DIRECTORY_SEPARATOR . ucfirst($enumName) . '.php';
        $file = fopen($path, 'w+');
        if ($file === false) {
            throw new FileNotWritable('can\'t open "' . $path . '" with write permission');
        }
        $path .= 'Base' . DIRECTORY_SEPARATOR . ucfirst($enumName) . '.php';
        $content = "<?php\n\nnamespace " . ltrim(rtrim($mapping['config']['models']['namespace'], '\\'), '\\') . "\\Base;\n\nuse RocknRoot\StrayFw\Database\Provider\Enum;\n";
        $content .= "\nclass " . ucfirst($enumName) . " extends Enum\n{\n";
        $content .= "    public function getDatabaseName() : string\n    {\n        return '" . $mapping['config']['database'] . "';\n    }\n\n";
        $content .= "    public function getTableName() : string\n    {\n        return '" . $enumRealName . "';\n    }\n\n";
        $content .= $consts . "\n}";
        if (fwrite($file, $content) === false) {
            throw new FileNotWritable('can\'t write in "' . $path . '"');
        }
        fclose($file);

        $path = rtrim($mapping['config']['models']['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        $path .= ucfirst($enumName) . '.php';
        if (file_exists($path) === false) {
            $file = fopen($path, 'w+');
            if ($file === false) {
                throw new FileNotWritable('can\'t open "' . $path . '" with write permission');
            }
            $content = "<?php\n\nnamespace " . ltrim(rtrim($mapping['config']['models']['namespace'], '\\'), '\\') . ";\n\nuse " . rtrim($mapping['config']['models']['namespace'], '\\') . "\\Base\\" . ucfirst($enumName) . " as BaseEnum;\n\nclass " . ucfirst($enumName) . " extends BaseEnum\n{\n}";
            if (fwrite($file, $content) === false) {
                throw new FileNotWritable('can\'t write in "' . $path . '"');
            }
        }

        echo $enumName . ' - Done' . PHP_EOL;
    }
private function generateEnum ( string $ enumName , array $ enumDefinition ) { $ definition = $ this -> getDefinition ( ) ; $ consts = null ; $ enumRealName = null ; if ( isset ( $ enumDefinition [ 'name' ] ) === true ) { $ enumRealName = $ enumDefinition [ 'name' ] ; } else { $ enumRealName = Helper :: codifyName ( $ this -> mapping ) . '_' . Helper :: codifyName ( $ enumName ) ; } if ( isset ( $ enumDefinition [ 'values' ] ) === false ) { throw new InvalidSchemaDefinition ( 'enum "' . $ enumName . '" has no value' ) ; } foreach ( $ enumDefinition [ 'values' ] as $ valueName => $ valueAlias ) { $ valueRealName = null ; if ( is_string ( $ valueName ) === true ) { $ valueRealName = $ valueName ; } else { $ valueRealName = Helper :: codifyName ( $ enumName ) . '_' . Helper :: codifyName ( $ valueAlias ) ; } $ consts .= '    const VALUE_' . strtoupper ( Helper :: codifyName ( $ valueAlias ) ) . ' = \'' . $ enumRealName . '.' . $ valueRealName . "';\n" ; } $ mapping = Mapping :: get ( $ this -> mapping ) ; $ path = rtrim ( $ mapping [ 'config' ] [ 'models' ] [ 'path' ] , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; $ path .= 'Base' . DIRECTORY_SEPARATOR . ucfirst ( $ enumName ) . '.php' ; $ file = fopen ( $ path , 'w+' ) ; if ( $ file === false ) { throw new FileNotWritable ( 'can\'t open "' . $ path . '" with write permission' ) ; } $ path .= 'Base' . DIRECTORY_SEPARATOR . ucfirst ( $ enumName ) . '.php' ; $ content = "<?php\n\nnamespace " . ltrim ( rtrim ( $ mapping [ 'config' ] [ 'models' ] [ 'namespace' ] , '\\' ) , '\\' ) . "\\Base;\n\nuse RocknRoot\StrayFw\Database\Provider\Enum;\n" ; $ content .= "\nclass " . ucfirst ( $ enumName ) . " extends Enum\n{\n" ; $ content .= "    public function getDatabaseName() : string\n    {\n        return '" . $ mapping [ 'config' ] [ 'database' ] . "';\n    }\n\n" ; $ content .= "    public function getTableName() : string\n    {\n        return '" . $ enumRealName . "';\n    }\n\n" ; $ content .= $ consts . "\n}" ; if ( fwrite ( $ file , $ content ) === false ) { throw new FileNotWritable ( 'can\'t write in "' . $ path . '"' ) ; } fclose ( $ file ) ; $ path = rtrim ( $ mapping [ 'config' ] [ 'models' ] [ 'path' ] , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; $ path .= ucfirst ( $ enumName ) . '.php' ; if ( file_exists ( $ path ) === false ) { $ file = fopen ( $ path , 'w+' ) ; if ( $ file === false ) { throw new FileNotWritable ( 'can\'t open "' . $ path . '" with write permission' ) ; } $ content = "<?php\n\nnamespace " . ltrim ( rtrim ( $ mapping [ 'config' ] [ 'models' ] [ 'namespace' ] , '\\' ) , '\\' ) . ";\n\nuse " . rtrim ( $ mapping [ 'config' ] [ 'models' ] [ 'namespace' ] , '\\' ) . "\\Base\\" . ucfirst ( $ enumName ) . " as BaseEnum;\n\nclass " . ucfirst ( $ enumName ) . " extends BaseEnum\n{\n}" ; if ( fwrite ( $ file , $ content ) === false ) { throw new FileNotWritable ( 'can\'t write in "' . $ path . '"' ) ; } } echo $ enumName . ' - Done' . PHP_EOL ; }
Generate classes for a enum.

@param string $enumName enum alias
@param array $enumDefinition enum definition from a schema file
@throws InvalidSchemaDefinition if an enum has no values defined
@throws FileNotWritable         if a base file can't be opened with write permission
@throws FileNotWritable         if a user file can't be opened with write permission
Generate classes for a enum .