{"id":36994767,"url":"https://github.com/josezenem/php-enums-extended","last_synced_at":"2026-01-13T23:47:02.100Z","repository":{"id":41876660,"uuid":"454610747","full_name":"josezenem/php-enums-extended","owner":"josezenem","description":"PHP 8.1 Enums Extended, gives you the ability to use additional methods to work with PHP 8.1 Enums.","archived":false,"fork":false,"pushed_at":"2026-01-12T07:14:29.000Z","size":77,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-12T17:19:48.873Z","etag":null,"topics":["enums","laravel","php"],"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/josezenem.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"josezenem"}},"created_at":"2022-02-02T01:38:28.000Z","updated_at":"2026-01-12T07:14:26.000Z","dependencies_parsed_at":"2025-05-12T07:35:40.524Z","dependency_job_id":null,"html_url":"https://github.com/josezenem/php-enums-extended","commit_stats":{"total_commits":40,"total_committers":4,"mean_commits":10.0,"dds":0.55,"last_synced_commit":"99b364f282f0c2823e8be17a1dc6bae07a41faeb"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/josezenem/php-enums-extended","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josezenem%2Fphp-enums-extended","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josezenem%2Fphp-enums-extended/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josezenem%2Fphp-enums-extended/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josezenem%2Fphp-enums-extended/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josezenem","download_url":"https://codeload.github.com/josezenem/php-enums-extended/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josezenem%2Fphp-enums-extended/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["enums","laravel","php"],"created_at":"2026-01-13T23:47:02.026Z","updated_at":"2026-01-13T23:47:02.083Z","avatar_url":"https://github.com/josezenem.png","language":"PHP","funding_links":["https://github.com/sponsors/josezenem"],"categories":[],"sub_categories":[],"readme":"# PHP 8.1 Enums Extended\n\n[![Latest Stable Version](http://poser.pugx.org/josezenem/php-enums-extended/v)](https://packagist.org/packages/josezenem/php-enums-extended)\n[![Tests](https://github.com/josezenem/php-enums-extended/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/josezenem/php-enums-extended/actions/workflows/run-tests.yml)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/0bd2399747f045e78039e72d51a87355)](https://www.codacy.com/gh/josezenem/php-enums-extended/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=josezenem/php-enums-extended\u0026amp;utm_campaign=Badge_Grade)\n[![Total Downloads](https://img.shields.io/packagist/dt/josezenem/php-enums-extended.svg?style=flat-square)](https://packagist.org/packages/josezenem/php-enums-extended)\n[![PHP Version Require](http://poser.pugx.org/josezenem/php-enums-extended/require/php)](https://packagist.org/packages/josezenem/php-enums-extended)\n\nPHP 8.1 Enums Extended, gives you the ability to use additional methods to work with PHP 8.1 Enums.\n\n```php\nenum StatusEnum:int\n{\n    case Closed = 0;\n    case Open = 1;\n    case PENDING_APPROVAL = 2;\n}\n\n// Given a new Blog() that uses the enum trait, you can do things like:\n$blog-\u003estatus-\u003eisOpen() // Will return boolean\n$blog-\u003estatus-\u003eequals(StatusEnum::Open, StatusEnum::Closed)\n\n// Normalization happens in the background allowing these scenarios \n$blog-\u003estatus-\u003eisPendingApproval();\n$blog-\u003estatus-\u003eisPENDING_APPROVAL();\n\nStatusEnum::Open() // Will return -\u003evalue, vs doing StatusEnum::Open-\u003evalue\nStatusEnum::PendingApproval()\nStatusEnum::PENDING_APPROVAL()\n```\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require josezenem/php-enums-extended\n```\n\n## Usage\n\n\u003ca name=\"available-methods\"\u003e\u003c/a\u003e\n## [`Available Methods`](#available-methods)\n\n- [`equals()`](#method-equals)\n- [`doesNotEqual()`](#method-does-not-equal)\n- [`isCall**()`](#method-is-call)\n\n\u003ca name=\"available-static-methods\"\u003e\u003c/a\u003e\n## [`Available Static Methods`](#available-static-methods)\n- [`options()`](#static-method-to-options-array)\n- [`optionsFlipped()`](#static-method-to-options-flipped-array)\n- [`names()`](#static-method-to-names-array)\n- [`hasName()`](#static-method-has-name)\n- [`values()`](#static-method-to-values-array)\n- [`hasValue()`](#static-method-has-value)\n- [`call**()`](#static-method-call)\n\n\u003ca name=\"method-equals\"\u003e\u003c/a\u003e\n### `equals()`\nPass one or multiple Enum cases, will return boolean if one matches.\n```php\n$blog-\u003estatus-\u003eequals(StatusEnum::Closed, StatusEnum::Draft);\n```\n\u003ca name=\"method-does-not-equal\"\u003e\u003c/a\u003e\n### `doesNotEqual()`\nPass one or multiple Enum cases, will return boolean if it does not match.\n```php\n$blog-\u003estatus-\u003edoesNotEqual(StatusEnum::Closed, StatusEnum::Draft);\n```\n\u003ca name=\"method-is-call\"\u003e\u003c/a\u003e\n### `isCall**()`\nReturns boolean if the current value matches the desired case.  Methods with underscores can be accessed via camel case, as well as their regular name.\n```php\n$blog-\u003estatus-\u003eisDraft();\n\n// Given StatusEnum::OPEN_ISSUE = 4;\n// the following is acceptable.\n$blog-\u003estatus-\u003eisOpenIssue();\n$blog-\u003estatus-\u003eisOPEN_ISSUE();\n```\n\u003ca name=\"static-method-to-options-array\"\u003e\u003c/a\u003e\n### `options()`\nWill return an array of $val =\u003e $key.\n```php\n$options = self::options()\n\n// returns\n$options = [\n    'open' =\u003e 'Open',\n    'closed' =\u003e 'Closed',\n    'draft' =\u003e 'Draft',\n]\n```\n\u003ca name=\"static-method-to-options-flipped-array\"\u003e\u003c/a\u003e\n### `optionsFlipped()`\nWill return an array of $key =\u003e $val.\n```php\n$options = self::optionsFlipped()\n\n// returns\n$options = [\n    'Open' =\u003e 'open',\n    'Closed' =\u003e 'closed',\n    'Draft' =\u003e 'draft',\n]\n```\n\u003ca name=\"static-method-to-names-array\"\u003e\u003c/a\u003e\n### `names()`\nWill return an array of only names\n```php\n$options = self::names()\n\n// returns\n$options = [\n    'Open' =\u003e 'Open',\n    'Closed' =\u003e 'Closed',\n    'Draft' =\u003e 'Draft',\n]\n```\n\u003ca name=\"static-method-has-name\"\u003e\u003c/a\u003e\n### `hasName()`\nPass variable and confirm if the name is valid for the Enum\n```php\nApp\\MyEnums\\Type::hasName('Closed');\n// Returns true\n\nApp\\MyEnums\\Type::hasName('close');\n// Returns false\n```\n\u003ca name=\"static-method-to-values-array\"\u003e\u003c/a\u003e\n### `values()`\nWill return an array of only values\n```php\n$options = self::values()\n\n// returns\n$options = [\n    'open' =\u003e 'open',\n    'closed' =\u003e 'closed',\n    'draft' =\u003e 'draft',\n]\n```\n\u003ca name=\"static-method-has-value\"\u003e\u003c/a\u003e\n### `hasValue()`\nPass variable and confirm if the value is valid for the Enum\n```php\nApp\\MyEnums\\Type::hasValue('closed');\n// Returns true\n\nApp\\MyEnums\\Type::hasValue('not a valid value for the enum');\n// Returns false\n```\n\u003ca name=\"static-method-call\"\u003e\u003c/a\u003e\n### `call**()`\nWill allow you to grab the value of a field by calling it statically.\n```php\n// Consider the following scenario, to get the value you would do:\n// StatusEnum::Open-\u003evalue\nenum StatusEnum:int\n{\n    case Closed = 0;\n    case Open = 1;\n    case Draft = 2;\n}\n\n// You can instead get value directy by calling it statically\n// Case Insensitive\nStatusEnum::OPEN()\nStatusEnum::Open()\n```\n\n### Exception Handler\nWhen using the magic methods, if the method calls do not exist, the system will throw\n\n```\nJosezenem\\PhpEnumsExtended\\Exceptions\\EnumsExtendedException\n```\n\n```php\n// StatusEnum.php\n// StatusEnum:int is used for the example, but supports :string and default of just StatusEnum\nuse Josezenem\\PhpEnumsExtended\\Traits\\PhpEnumsExtendedTrait;\n\nenum StatusEnum:int\n{\n    use PhpEnumsExtendedTrait;\n\n    case Closed = 0;\n    case Open = 1;\n    case Draft = 2;\n}\n\n// Blog.php\nclass Blog\n{\n    public function __construct(\n        public StatusEnum $status = StatusEnum::Open,\n    ) {\n    }\n}\n\n\n\n// Usage\n$blog = new Blog();\n\n\n// -\u003eequals()\n$blog-\u003estatus-\u003eequals(StatusEnum::Open); // will return true if it matches\n$blog-\u003estatus-\u003eequals(StatusEnum::Closed, StatusEnum::Open); // Pass any number of params, will return true if it matches any of the parameters\n\n// -\u003edoesNotEqual()\n$blog-\u003estatus-\u003edoesNotEqual(StatusEnum::Closed); // will return true if it does not match\n$blog-\u003estatus-\u003edoesNotEqual(StatusEnum::Closed, StatusEnum::Draft)  // Pass any number of params, will return true if it does not match any of the parameters\n\n// -\u003eis** magic method\n// the magic method takes camelCase allowing you to do boolean check against any field.\n$blog-\u003estatus-\u003eisOpen() // will return true or false\n\n// ::options()\n$options = StatusEnum::options();\n\n// will output\n//$options = [\n//    0 =\u003e 'Closed',\n//    1 =\u003e 'Open',\n//    2 =\u003e 'Closed',\n//];\n\n// ::optionsFlipped()\n$options = StatusEnum::optionsFlipped();\n\n// will output\n//$options = [\n//    'Closed' =\u003e 0,\n//    'Open' =\u003e 1,\n//    'Closed' =\u003e 2,\n//];\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Jose Jimenez](https://github.com/josezenem)\n- [All Contributors](../../contributors)\n- Special Thanks to [Shocm](https://twitter.com/shocm) for pushing me to make this, and answering my late replies.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosezenem%2Fphp-enums-extended","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosezenem%2Fphp-enums-extended","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosezenem%2Fphp-enums-extended/lists"}