PHP code example of iqomp / enum

1. Go to this page and download the library: Download iqomp/enum 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/ */

    

iqomp / enum example snippets




return [
    'enums' => [
        'gender' => [
            '0' => 'Unknown',
            '1' => 'Male',
            '2' => 'Female',
            '3' => 'Non-Binary'
        ]
    ]
];



// ...
class ConfigProvider
{
    public function __invoke()
    {
        return [
            'enum' => [
                'enums' => [
                    'gender' => [
                        '0' => 'Unknown',
                        '1' => 'Male',
                        '2' => 'Female',
                        '3' => 'Non-Binary'
                    ]
                ]
            ]
        ];
    }
}


// gender.php

return [
    'Unknown'    => 'Unknown',
    'Female'     => 'Female',
    'Male'       => 'Male',
    'Non-Binary' => 'Non Binary'
];



use Iqomp\Enum\Enum;

// $enum = new Enum('gender', '1', 'int');
$enum = new Enum('std-gender', '2', 'str');

$enum->value;
$enum->options;
$enum->label;

    // ...
    'rules' => [
        'enum' => 'std-gender'
    ]
    // ...

    // ...
    '/field/' => [
        'type' => 'enum',
        'enum' => 'std-gender'
    ]
    // ...

    // ...
    '/field/' => [
        'type' => 'multiple-enum',
        'enum' => 'std-gender',
        'separator' => ',' // PHP_EOL, 'json'
    ]
    // ...
bash
php bin/hyperf.php vendor:publish iqomp/enum