{"id":38526961,"url":"https://github.com/iqomp/enum","last_synced_at":"2026-01-17T06:48:35.916Z","repository":{"id":56993316,"uuid":"315562042","full_name":"iqomp/enum","owner":"iqomp","description":"Static data enum provider.","archived":false,"fork":false,"pushed_at":"2021-04-29T04:55:40.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-26T20:10:00.511Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iqomp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-24T08:11:22.000Z","updated_at":"2021-04-29T04:55:43.000Z","dependencies_parsed_at":"2022-08-21T10:40:39.857Z","dependency_job_id":null,"html_url":"https://github.com/iqomp/enum","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/iqomp/enum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqomp%2Fenum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqomp%2Fenum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqomp%2Fenum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqomp%2Fenum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iqomp","download_url":"https://codeload.github.com/iqomp/enum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iqomp%2Fenum/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28502916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T04:31:57.058Z","status":"ssl_error","status_checked_at":"2026-01-17T04:31:45.816Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-17T06:48:31.576Z","updated_at":"2026-01-17T06:48:35.905Z","avatar_url":"https://github.com/iqomp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iqomp/enum\n\nStatic data enum provider. This module provide list of enums that may used by\napplication.\n\n## Installation\n\n```bash\ncomposer require iqomp/enum\n```\n\n## Publishing Config\n\n```bash\nphp bin/hyperf.php vendor:publish iqomp/enum\n```\n\n## Configuration\n\nTo add new enum data or modify exists one, modify file on\n`/config/autoload/enum.php` to return data as below:\n\n```php\n\u003c?php\n\nreturn [\n    'enums' =\u003e [\n        'gender' =\u003e [\n            '0' =\u003e 'Unknown',\n            '1' =\u003e 'Male',\n            '2' =\u003e 'Female',\n            '3' =\u003e 'Non-Binary'\n        ]\n    ]\n];\n```\n\nOr if you prefer to use file `ConfigProvider.php`, add data as below:\n\n```php\n\u003c?php\n\n// ...\nclass ConfigProvider\n{\n    public function __invoke()\n    {\n        return [\n            'enum' =\u003e [\n                'enums' =\u003e [\n                    'gender' =\u003e [\n                        '0' =\u003e 'Unknown',\n                        '1' =\u003e 'Male',\n                        '2' =\u003e 'Female',\n                        '3' =\u003e 'Non-Binary'\n                    ]\n                ]\n            ]\n        ];\n    }\n}\n```\n\nMake sure to update your `composer.json` file to let hyperf identify the config file:\n\n```json\n    \"extra\": {\n        \"hyperf\": {\n            \"config\": \"Vendor\\\\Module\\\\ConfigProvider\"\n        }\n    }\n```\n\n## Translation\n\nIf you want the enum label to be translated, make sure to install module\n[hyperf/translation](https://github.com/hyperf/translation). Add new translation\non folder `storage/languages/vendor/enum/{locale}/{enum-name}.php`.\n\n```php\n\u003c?php\n// gender.php\n\nreturn [\n    'Unknown'    =\u003e 'Unknown',\n    'Female'     =\u003e 'Female',\n    'Male'       =\u003e 'Male',\n    'Non-Binary' =\u003e 'Non Binary'\n];\n```\n\n## Usage\n\nUse class `Iqomp\\Enum\\Enum` to create enum object with specified value.\n\n```php\n\u003c?php\n\nuse Iqomp\\Enum\\Enum;\n\n// $enum = new Enum('gender', '1', 'int');\n$enum = new Enum('std-gender', '2', 'str');\n\n$enum-\u003evalue;\n$enum-\u003eoptions;\n$enum-\u003elabel;\n```\n\n## Method\n\nList of method defined by this class object:\n\n### __construct(string $name, $value=null, string $type=null): Enum\n\nCreate new Enum object. This method accept parameters:\n\n1. `name::string` The name of enum datalist.\n1. `value::int|str` The value of enum item.\n1. `type::string` Convert provided value as `int` or `str`.\n\n### __get($name): mixed\n\nGet enum data property, accepted name are `value`, `label`, and `options`.\n\n### __toString(): string\n\nReturn string enum label.\n\n### jsonSerialize()\n\nConvert the enum to json_encode ready parameter.\n\n## Form Validator\n\nIf you're using validator [iqomp/validator](https://github.com/iqomp/validator/)\nfor your object or form validator, this module add new form validator rule named\n`enum` to validate if user provided data is in registered enum.\n\n### enum =\u003e name\n\nMake sure user provided value is in registered enum, the value of user posted data\ncan be single int/str or array of it.\n\n```php\n    // ...\n    'rules' =\u003e [\n        'enum' =\u003e 'std-gender'\n    ]\n    // ...\n```\n\n## Linter\n\nRun below script to run psr-12 linter:\n\n```bash\ncomposer lint\n```\n\n## Formatter\n\nIf you're using formatter [iqomp/formatter](https://github.com/iqomp/formatter/)\nfor your object formatter, this module add new object format type named `enum`\nand `multiple-enum` that can be use to convert object property value to enum\nobject.\n\n### enum\n\nConvert current object property value to `Iqomp\\Enum\\Enum` object.\n\n\n```php\n    // ...\n    '/field/' =\u003e [\n        'type' =\u003e 'enum',\n        'enum' =\u003e 'std-gender'\n    ]\n    // ...\n```\n\n### multiple-enum\n\nConvert current object property value to array of `Iqomp\\Enum\\Enum` with custom\nseparator:\n\n```php\n    // ...\n    '/field/' =\u003e [\n        'type' =\u003e 'multiple-enum',\n        'enum' =\u003e 'std-gender',\n        'separator' =\u003e ',' // PHP_EOL, 'json'\n    ]\n    // ...\n```\n\nIf property `separator` is not set, `PHP_EOL` will be used. It also accept\nseparator `'json'` that will use `json_decode` for separation. If the value of\nobject property is already array, no separation/explode will used.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiqomp%2Fenum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiqomp%2Fenum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiqomp%2Fenum/lists"}