{"id":15027727,"url":"https://github.com/othyn/php-enum-enhancements","last_synced_at":"2025-10-30T20:31:35.997Z","repository":{"id":57033633,"uuid":"459687749","full_name":"othyn/php-enum-enhancements","owner":"othyn","description":"Adds some helpful enum traits to the glorious new PHP Enum type, like value lists and value arrays.","archived":false,"fork":false,"pushed_at":"2022-08-13T03:26:51.000Z","size":221,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-02T12:42:18.199Z","etag":null,"topics":["php","php-enum","php-extension","php-extensions","php-library","php8","php81"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/othyn.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":"2022-02-15T17:48:00.000Z","updated_at":"2024-10-02T01:45:10.000Z","dependencies_parsed_at":"2022-08-23T20:50:29.766Z","dependency_job_id":null,"html_url":"https://github.com/othyn/php-enum-enhancements","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2Fphp-enum-enhancements","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2Fphp-enum-enhancements/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2Fphp-enum-enhancements/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2Fphp-enum-enhancements/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/othyn","download_url":"https://codeload.github.com/othyn/php-enum-enhancements/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239053459,"owners_count":19574152,"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":["php","php-enum","php-extension","php-extensions","php-library","php8","php81"],"created_at":"2024-09-24T20:06:57.092Z","updated_at":"2025-10-30T20:31:30.655Z","avatar_url":"https://github.com/othyn.png","language":"HTML","readme":"# PHP Enum Enhancements\n\n[![Tests](https://github.com/othyn/php-enum-enhancements/actions/workflows/phpunit.yml/badge.svg)](https://github.com/othyn/php-enum-enhancements/actions/workflows/phpunit.yml)\n[![Code Style](https://github.com/othyn/php-enum-enhancements/actions/workflows/phpcsfixer.yml/badge.svg)](https://github.com/othyn/php-enum-enhancements/actions/workflows/phpcsfixer.yml)\n[![Downloads](https://img.shields.io/packagist/dt/othyn/php-enum-enhancements?color=green)](#installation)\n[![GitHub license](https://img.shields.io/github/license/othyn/php-enum-enhancements)](https://github.com/othyn/php-enum-enhancements/blob/main/LICENSE)\n[![Love](https://img.shields.io/badge/built%20with-love-red)](https://img.shields.io/badge/built%20with-love-red)\n\nA [Composer](https://getcomposer.org/) package for [PHP](https://www.php.net/) that adds some helpful enum traits to the glorious new PHP [Enum](https://www.php.net/manual/en/language.enumerations.php) type.\n\nThe package so far provides;\n\n- A handy trait that extends PHP's native Enum type\n- Adds a new static `UnitEnum::valueArray(): array` method that returns all values within an Enum as an equally typed array of Enum values\n- Adds a new static `UnitEnum::valueList(string $separator = ', '): string` method that returns all values within an Enum as a comma separated list string\n\nThe package is available on Packagist as [othyn/php-enum-enhancements](https://packagist.org/packages/othyn/php-enum-enhancements).\n\n---\n\n## Installation\n\nHop into your project that you wish to install it in and run the following Composer command to grab the latest version:\n\n```sh\ncomposer require othyn/php-enum-enhancements\n```\n\n---\n\n## Usage\n\nFor more comprehensive usage examples, you can view the test suite. However I'll show some basic usage examples below.\n\n### Enum: Value Array\n\n```php\n\u003c?php\n\nnamespace App\\Enums;\n\nuse Othyn\\PhpEnumEnhancements\\Traits\\EnumEnhancements;\n\nenum TestEnum\n{\n    use EnumEnhancements;\n\n    case Alpha;\n    case Bravo;\n    case Charlie;\n    case Delta;\n    case Echo;\n}\n\nvar_dump(TestEnum::valueArray());\n\n// Results in the following being printed:\n// array(5) {\n//   [0]=\u003e\n//   string(5) \"Alpha\"\n//   [1]=\u003e\n//   string(5) \"Bravo\"\n//   [2]=\u003e\n//   string(7) \"Charlie\"\n//   [3]=\u003e\n//   string(5) \"Delta\"\n//   [4]=\u003e\n//   string(4) \"Echo\"\n// }\n```\n\n### Enum: Value List\n\n```php\n\u003c?php\n\nnamespace App\\Enums;\n\nuse Othyn\\PhpEnumEnhancements\\Traits\\EnumEnhancements;\n\nenum TestEnum\n{\n    use EnumEnhancements;\n\n    case Alpha;\n    case Bravo;\n    case Charlie;\n    case Delta;\n    case Echo;\n}\n\nvar_dump(TestEnum::valueList());\n\n// Results in the following being printed:\n// string(34) \"Alpha, Bravo, Charlie, Delta, Echo\"\n\nvar_dump(TestEnum::valueList(separator: ':'));\n\n// Results in the following being printed:\n// string(30) \"Alpha:Bravo:Charlie:Delta:Echo\"\n```\n\n### Backed String Enum: Value Array\n\n```php\n\u003c?php\n\nnamespace App\\Enums;\n\nuse Othyn\\PhpEnumEnhancements\\Traits\\EnumEnhancements;\n\nenum TestStringBackedEnum: string\n{\n    use EnumEnhancements;\n\n    case Alpha   = 'alpha';\n    case Bravo   = 'bravo';\n    case Charlie = 'charlie';\n    case Delta   = 'delta';\n    case Echo    = 'echo';\n}\n\nvar_dump(TestStringBackedEnum::valueArray());\n\n// Results in the following being printed:\n// array(5) {\n//   [0]=\u003e\n//   string(5) \"alpha\"\n//   [1]=\u003e\n//   string(5) \"bravo\"\n//   [2]=\u003e\n//   string(7) \"charlie\"\n//   [3]=\u003e\n//   string(5) \"delta\"\n//   [4]=\u003e\n//   string(4) \"echo\"\n// }\n```\n\n### Backed String Enum: Value List\n\n```php\n\u003c?php\n\nnamespace App\\Enums;\n\nuse Othyn\\PhpEnumEnhancements\\Traits\\EnumEnhancements;\n\nenum TestStringBackedEnum: string\n{\n    use EnumEnhancements;\n\n    case Alpha   = 'alpha';\n    case Bravo   = 'bravo';\n    case Charlie = 'charlie';\n    case Delta   = 'delta';\n    case Echo    = 'echo';\n}\n\nvar_dump(TestStringBackedEnum::valueList());\n\n// Results in the following being printed:\n// string(34) \"alpha, bravo, charlie, delta, echo\"\n\nvar_dump(TestStringBackedEnum::valueList(separator: ':'));\n\n// Results in the following being printed:\n// string(30) \"alpha:bravo:charlie:delta:echo\"\n```\n\n### Backed Int Enum: Value Array\n\n```php\n\u003c?php\n\nnamespace App\\Enums;\n\nuse Othyn\\PhpEnumEnhancements\\Traits\\EnumEnhancements;\n\nenum TestIntBackedEnum: int\n{\n    use EnumEnhancements;\n\n    case One   = 1;\n    case Two   = 2;\n    case Three = 3;\n    case Four  = 4;\n    case Five  = 5;\n}\n\nvar_dump(TestIntBackedEnum::valueArray());\n\n// Results in the following being printed:\n// array(5) {\n//   [0]=\u003e\n//   int(1)\n//   [1]=\u003e\n//   int(2)\n//   [2]=\u003e\n//   int(3)\n//   [3]=\u003e\n//   int(4)\n//   [4]=\u003e\n//   int(5)\n// }\n```\n\n### Backed Int Enum: Value List\n\n```php\n\u003c?php\n\nnamespace App\\Enums;\n\nuse Othyn\\PhpEnumEnhancements\\Traits\\EnumEnhancements;\n\nenum TestIntBackedEnum: int\n{\n    use EnumEnhancements;\n\n    case One   = 1;\n    case Two   = 2;\n    case Three = 3;\n    case Four  = 4;\n    case Five  = 5;\n}\n\nvar_dump(TestIntBackedEnum::valueList());\n\n// Results in the following being printed:\n// string(13) \"1, 2, 3, 4, 5\"\n\nvar_dump(TestIntBackedEnum::valueList(separator: ':'));\n\n// Results in the following being printed:\n// string(9) \"1:2:3:4:5\"\n```\n\n---\n\n## Development\n\nMost development processes are wrapped up in an easy to use Docker container.\n\n### Enforcing Style\n\nThe projects `.php-cs-fixer.dist.php` config contains the rules that this repo conforms to and will run against the `./src` and `./tests` directory.\n\nFor remote style enforcement there is a GitHub Action configured to automatically run `phpcsfixer`.\n\nFor local style enforcement there is a composer script `composer style` configured to run `phpcsfixer`.\n\n### Testing\n\nFor remote testing there is a GitHub Action setup to automatically run the test suite on the `main` branch or and PR branches.\n\nFor local testing there is a Docker container that is pre-built that contains an Alpine CLI release of PHP + PHPUnit + xdebug. This is setup to test the project and can be setup via the following:\n\n```sh\ncomposer docker-build\n```\n\nThis should trigger Docker Compose to build the image. You can then up the container via the following:\n\n```sh\ncomposer docker-up\n```\n\nThere are tests for all code written, in which can be run via:\n\n```sh\n# PHPUnit with code coverage report\ncomposer test\n\n# PHPUnit with code coverage report, using local phpunit and xdebug\ncomposer test-local\n```\n\nIn those tests, there are Feature tests for a production ready implementation of the package. There are no Unit tests at present.\n\nYou can also easily open a shell in the testing container by using the command:\n\n```sh\ncomposer docker-shell\n```\n\n---\n\n## Changelog\n\nAny and all project changes for releases should be documented below. Versioning follows the [SemVer](https://semver.org/) standard.\n\n---\n\n### Version 1.0.1\n\n[[Git Changes]](https://github.com/othyn/php-enum-enhancements/compare/v1.0.0...v1.0.1) README changes.\n\n#### Added\n\n- Everything\n\n#### Changed\n\n- SemVer verbiage and link change in the README.\n- Change usage examples in the readme to instead utilise `var_dump` to demonstrate the resulting types within the array returned from `UnitEnum::valueArray()`.\n- Utilised the `UnitEnum` base type within the docs in code examples where a test Enum is not present.\n\n#### Fixed\n\n- Everything\n\n#### Removed\n\n- Nothing\n\n---\n\n### Version 1.0.0\n\n[[Git Changes]](https://github.com/othyn/php-enum-enhancements/compare/39afaf2a6a2c2238f1e8180aaa7ab7a33d79940c...v1.0.0) Initial release.\n\n#### Added\n\n- Everything\n\n#### Changed\n\n- Everything\n\n#### Fixed\n\n- Everything\n\n#### Removed\n\n- Nothing\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothyn%2Fphp-enum-enhancements","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fothyn%2Fphp-enum-enhancements","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothyn%2Fphp-enum-enhancements/lists"}