{"id":15027131,"url":"https://github.com/teodoroleckie/enum","last_synced_at":"2026-02-04T06:32:22.268Z","repository":{"id":57070532,"uuid":"362529712","full_name":"teodoroleckie/enum","owner":"teodoroleckie","description":"⚡ PHP Enum. One advantage over using class constants is to be able to use an enum as a parameter type","archived":false,"fork":false,"pushed_at":"2021-05-13T08:49:56.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T20:28:31.913Z","etag":null,"topics":["enum","enum-object","enumeration","php","php-8","php-enum","php-enum-object","php-enumeration","php-enumerator"],"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/teodoroleckie.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":["teodoroleckie"],"custom":["https://www.paypal.com/donate?business=ZHYA2MTGA4884\u0026currency_code=USD"]}},"created_at":"2021-04-28T16:02:55.000Z","updated_at":"2021-05-13T08:49:59.000Z","dependencies_parsed_at":"2022-08-24T14:54:22.792Z","dependency_job_id":null,"html_url":"https://github.com/teodoroleckie/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/teodoroleckie%2Fenum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Fenum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Fenum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Fenum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teodoroleckie","download_url":"https://codeload.github.com/teodoroleckie/enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243330320,"owners_count":20274039,"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":["enum","enum-object","enumeration","php","php-8","php-enum","php-enum-object","php-enumeration","php-enumerator"],"created_at":"2024-09-24T20:05:49.841Z","updated_at":"2026-02-04T06:32:17.216Z","avatar_url":"https://github.com/teodoroleckie.png","language":"PHP","readme":"# PHP Enum object\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/tleckie/enum.svg?style=flat-square)](https://packagist.org/packages/tleckie/enum)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/teodoroleckie/enum/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/enum/?branch=main)\n[![Build Status](https://scrutinizer-ci.com/g/teodoroleckie/enum/badges/build.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/enum/build-status/main)\n[![Total Downloads](https://img.shields.io/packagist/dt/tleckie/enum.svg?style=flat-square)](https://packagist.org/packages/tleckie/enum)\n[![Code Intelligence Status](https://scrutinizer-ci.com/g/teodoroleckie/enum/badges/code-intelligence.svg?b=main)](https://scrutinizer-ci.com/code-intelligence)\n\nEnumerator in php\n\n### Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require tleckie/enum\n```\n\n### Usage\n\nExtends Enum class and create your own type.\n\n```php\n\u003c?php\n\n/**\n * Class Vehicle\n *\n * @method static Vehicle CAR()\n * @method static Vehicle MOTORCYCLE()\n * @method static Vehicle BIKE()\n * @method static Vehicle TRICYCLE()\n * \n * @author Teodoro Leckie Westberg \u003cteodoroleckie@gmail.com\u003e\n */\nclass Vehicle extends Enum \n{\n    public const CAR = 1;\n    public const MOTORCYCLE = 2;\n    public const BIKE = 3;\n    public const TRICYCLE = 4;\n}\n\n$vehicle = new Vehicle(3);\n\n// Dynamic static methods available\n$vehicle::CAR();           // new Vehicle(1)\n$vehicle::MOTORCYCLE();    // new Vehicle(2)\n$vehicle::BIKE();          // new Vehicle(3)\n$vehicle::TRICYCLE();      // new Vehicle(4)\n.\n.\n.\nVehicle::CAR();           // new Vehicle(1)\nVehicle::MOTORCYCLE();    // new Vehicle(2)\nVehicle::BIKE();          // new Vehicle(3)\nVehicle::TRICYCLE();      // new Vehicle(4)\n```\n\n```php\n\npublic function edit(Vehicle $vehicle){\n    //...\n}\n\n$object-\u003eedit(Vehicle::CAR());\n\n```\n\n```php\n$vehicle = new Vehicle(3);\n\n$vehicle-\u003egetValue();  // int(3)\n$vehicle-\u003egetKey();    // \"BIKE\"\n```\n\n### getValues():\n```php\n$vehicle = new Vehicle(3);\n$vehicle-\u003egetValues(); // [1,2,3,4]\n```\n\n### getKeys():\n```php\n$vehicle = new Vehicle(3);\n$vehicle-\u003egetKeys();    //[\"CAR\",\"MOTORCYCLE\",\"BIKE\",\"TRICYCLE\"]\n```\n\n### toArray():\n\n```php\n$vehicle = new Vehicle(3);\n$vehicle-\u003etoArray();   //[\"CAR\" =\u003e 1,\"MOTORCYCLE\" =\u003e 2,\"BIKE\" =\u003e 3,\"TRICYCLE\" =\u003e 4]\n```\n\n### Cast string\n```php\n(string) Vehicle::MOTORCYCLE();             // \"2\"\n(string) new Vehicle(3);                    // \"3\"\n(string) new Vehicle( Vehicle::TRICYCLE() );// \"4\"\n(string) new Vehicle( new Vehicle(1) );     // \"1\"\n```\n","funding_links":["https://github.com/sponsors/teodoroleckie","https://www.paypal.com/donate?business=ZHYA2MTGA4884\u0026currency_code=USD"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteodoroleckie%2Fenum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteodoroleckie%2Fenum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteodoroleckie%2Fenum/lists"}