{"id":23980772,"url":"https://github.com/tailflow/enum","last_synced_at":"2025-04-14T04:33:48.618Z","repository":{"id":57064551,"uuid":"309045685","full_name":"tailflow/enum","owner":"tailflow","description":"PHP Enums","archived":false,"fork":false,"pushed_at":"2020-11-24T13:48:11.000Z","size":13,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T18:22:19.379Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tailflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-01T07:33:45.000Z","updated_at":"2023-08-27T15:52:25.000Z","dependencies_parsed_at":"2022-08-24T14:01:25.991Z","dependency_job_id":null,"html_url":"https://github.com/tailflow/enum","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailflow%2Fenum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailflow%2Fenum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailflow%2Fenum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailflow%2Fenum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tailflow","download_url":"https://codeload.github.com/tailflow/enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248822797,"owners_count":21167118,"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":[],"created_at":"2025-01-07T10:18:35.938Z","updated_at":"2025-04-14T04:33:48.598Z","avatar_url":"https://github.com/tailflow.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"https://packagist.org/packages/tailflow/enum\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/tailflow/enum.svg\" alt=\"Latest Version on Packagist\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/tailflow/enum/actions\"\u003e\u003cimg src=\"https://img.shields.io/github/workflow/status/tailflow/enum/default\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Introduction\n\nThe package offers strongly typed enums in PHP. In this package, enums are always objects, never constant values on their own. This allows for proper static analysis and refactoring in IDEs.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require tailflow/enum\n```\n\n## Usage\n\nHere is how enums are defined:\n\n```php\nuse Tailflow\\Enum\\Enum;\n\nclass Status extends Enum\n{\n    public const Inactive = 0;\n    public const Active = 1;\n    public const OnHold = 3;\n}\n```\n\nThis is how they are used:\n\n```php\n$class-\u003esetStatus(Status::Inactive);\n```\n\n### Custom enum labels\n\nBy default, enum labels are derived from the constant names. To get enum label, you can use `::getLabel` method on enum class:\n\n```php\n// $label will be equal to \"OnHold\" - the name of the constant\n$label = Status::getLabel(Status::OnHold); \n```\n\nOptionally, you can provide a different label for any given enum value:\n\n```php\nuse Tailflow\\Enum\\Enum;\n\nclass Status extends Enum\n{\n    public const Inactive = 0;\n    public const Active = 1;\n    public const OnHold = 3;\n\n    public static function labels(): array\n    {\n        return [\n            self::OnHold =\u003e 'waiting'\n        ];\n    }\n}\n\n// $label will be equal to \"waiting\" - the custom label defined in \"labels\" method\n$label = Status::getLabel(Status::OnHold); \n```\n\n## Listing all enum labels\n\nTo get a list of all labels of the enum, you can use `::getLabels` method:\n\n```php\n// $labels will contain the array - ['Inactive', 'Active', 'waiting']\n$labels = Status::getLabels(); \n```\n\n## Listing all enum values\n\nTo get a list of all values of the enum, you can use `::getValues` method:\n\n```php\n// $labels will contain the array - [0, 1, 3]\n$labels = Status::getValues(); \n```\n\n## License\n\nThe Laravel Orion is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftailflow%2Fenum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftailflow%2Fenum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftailflow%2Fenum/lists"}