{"id":22793177,"url":"https://github.com/ngmy/php-enum","last_synced_at":"2025-03-30T17:20:55.625Z","repository":{"id":51518090,"uuid":"338796733","full_name":"ngmy/php-enum","owner":"ngmy","description":"The enumeration type for PHP","archived":false,"fork":false,"pushed_at":"2021-05-11T12:36:46.000Z","size":138,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T19:11:07.834Z","etag":null,"topics":["array","enum","enum-map","enum-set","enumeration","library","map","php","php-library","set","type"],"latest_commit_sha":null,"homepage":"","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/ngmy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"ngmy","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://flattr.com/@ngmy"}},"created_at":"2021-02-14T12:07:34.000Z","updated_at":"2021-05-07T08:26:00.000Z","dependencies_parsed_at":"2022-08-03T06:01:00.494Z","dependency_job_id":null,"html_url":"https://github.com/ngmy/php-enum","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngmy%2Fphp-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngmy%2Fphp-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngmy%2Fphp-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngmy%2Fphp-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngmy","download_url":"https://codeload.github.com/ngmy/php-enum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246351394,"owners_count":20763293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["array","enum","enum-map","enum-set","enumeration","library","map","php","php-library","set","type"],"created_at":"2024-12-12T03:18:24.548Z","updated_at":"2025-03-30T17:20:55.587Z","avatar_url":"https://github.com/ngmy.png","language":"PHP","readme":"# PHP Enum\n[![Latest Stable Version](https://poser.pugx.org/ngmy/enum/v)](//packagist.org/packages/ngmy/enum)\n[![Total Downloads](https://poser.pugx.org/ngmy/enum/downloads)](//packagist.org/packages/ngmy/enum)\n[![Latest Unstable Version](https://poser.pugx.org/ngmy/enum/v/unstable)](//packagist.org/packages/ngmy/enum)\n[![License](https://poser.pugx.org/ngmy/enum/license)](//packagist.org/packages/ngmy/enum)\n[![composer.lock](https://poser.pugx.org/ngmy/enum/composerlock)](//packagist.org/packages/ngmy/enum)\n[![PHP CI](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml/badge.svg)](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml)\n[![Coverage Status](https://coveralls.io/repos/github/ngmy/php-enum/badge.svg?branch=master)](https://coveralls.io/github/ngmy/php-enum?branch=master)\n[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan)\n[![Psalm Coverage](https://shepherd.dev/github/ngmy/php-typed-array/coverage.svg?)](https://shepherd.dev/github/ngmy/php-typed-array)\n[![Psalm Level](https://shepherd.dev/github/ngmy/php-typed-array/level.svg?)](https://shepherd.dev/github/ngmy/php-typed-array)\n\nPHP Enum is the enumeration type for PHP.\n\n- Interface like the enum type of Java\n- Also provides the enum map and set like Java\n- Supports the static analysis like PHPStan and Psalm. Please see [examples](docs/examples)\n\n```php\n/**\n * @method static self FOO()\n * @method static self BAR()\n * @method static self BAZ()\n */\nclass Enum1 extends Ngmy\\Enum\\Enum\n{\n    /** @enum */\n    private static $FOO;\n    /** @enum */\n    private static $BAR;\n    /** @enum */\n    private static $BAZ;\n}\n\n// Returns the enum constant of the specified name\n$foo = Enum1::valueOf('FOO');\n$bar = Enum1::valueOf('BAR');\n$baz = Enum1::valueOf('BAZ');\n// You can also use magic factory methods\n$foo = Enum1::FOO();\n$bar = Enum1::BAR();\n$baz = Enum1::BAZ();\n\n// Returns the name of this enum constant, exactly as declared in its enum declaration\necho $foo-\u003ename() . PHP_EOL; // FOO\necho $bar-\u003ename() . PHP_EOL; // BAR\necho $baz-\u003ename() . PHP_EOL; // BAZ\n\n// Returns the name of this enum constant, as contained in the declaration\necho $foo . PHP_EOL; // FOO\necho $bar . PHP_EOL; // BAR\necho $baz . PHP_EOL; // BAZ\n\n// Returns the ordinal of this enum constant\necho $foo-\u003eordinal() . PHP_EOL; // 0\necho $bar-\u003eordinal() . PHP_EOL; // 1\necho $baz-\u003eordinal() . PHP_EOL; // 2\n\n// Returns true if the specified object is equal to this enum constant\necho var_export($foo-\u003eequals($foo), true) . PHP_EOL;                  // true\necho var_export($foo-\u003eequals(Enum1::valueOf('FOO')), true) . PHP_EOL; // true\necho var_export($foo-\u003eequals($bar), true) . PHP_EOL;                  // false\n\n// You can also have the enum constant with a value\n\n/**\n * @method static self FOO()\n * @method static self BAR()\n * @method static self BAZ()\n */\nclass Enum2 extends Ngmy\\Enum\\Enum\n{\n    /** @enum */\n    private static $FOO = 1;\n    /** @enum */\n    private static $BAR = 2;\n    /** @enum */\n    private static $BAZ = 3;\n\n    public function getValue(): int\n    {\n        return self::${$this-\u003ename()};\n    }\n}\n\necho Enum2::valueOf('FOO')-\u003egetValue() . PHP_EOL; // 1\necho Enum2::valueOf('BAR')-\u003egetValue() . PHP_EOL; // 2\necho Enum2::valueOf('BAZ')-\u003egetValue() . PHP_EOL; // 3\n```\n\n## Requirements\nPHP Enum has the following requirements:\n\n* PHP \u003e= 7.3\n\n## Installation\nExecute the Composer `require` command:\n```console\ncomposer require ngmy/enum\n```\n\n## Documentation\nPlease see the [API documentation](https://ngmy.github.io/php-enum/api/).\n\n## License\nPHP Enum is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).\n","funding_links":["https://github.com/sponsors/ngmy","https://flattr.com/@ngmy"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngmy%2Fphp-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngmy%2Fphp-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngmy%2Fphp-enum/lists"}