PHP code example of 4slv / enum-generator
1. Go to this page and download the library: Download 4slv/enum-generator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
4slv / enum-generator example snippets
use EnumGenerator\EnumElement;
use EnumGenerator\EnumGenerator;
enumNamespace = 'Enum';
$enumClassComment = 'Пол';
$enumCodeDirRelativePath = 'enum';
$enumElementList = [
(new EnumElement())->setName('MALE')->setValue('Male')->setComment('Мужчина'),
(new EnumElement())->setName('FEMALE')->setValue('Female')->setComment('Женщина')
];
$enumGenerator = new EnumGenerator();
$enumGenerator
->setProjectPath($projectPath) // $projectPath абсолютный путь к папке проекта
->setClassName($enumClassName) // $enumClassName название класса с перечислениями
->setEnumNamespace($enumNamespace) // $enumNamespace пространство имен класса с перечислениями
->setClassComment($enumClassComment) // $enumClassComment комментарий к классу с перечислениями
->setEnumCodeRelativePath($enumCodeDirRelativePath) // $enumCodeDirRelativePath относительный путь к папке
->setEnumElementList($enumElementList) // $enumElementList список описания элементов перечисления
->generate(); // генерация класса
namespace Enum;
use MyCLabs\Enum\Enum;
/** Пол */
class Sex extends Enum
{
/** Мужчина */
const MALE = 'Male';
/** Женщина */
const FEMALE = 'Female';
}