{"id":36999009,"url":"https://github.com/deltatag/enum","last_synced_at":"2026-01-14T00:00:57.433Z","repository":{"id":56965193,"uuid":"114928189","full_name":"deltatag/enum","owner":"deltatag","description":"Easy \u0026 simple enumerations for PHP","archived":false,"fork":false,"pushed_at":"2017-12-24T09:50:32.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2023-08-21T09:22:51.374Z","etag":null,"topics":["database","deltatag","enumeration","php","validation"],"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/deltatag.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":"2017-12-20T20:27:22.000Z","updated_at":"2019-03-04T20:52:13.000Z","dependencies_parsed_at":"2022-08-21T05:30:08.568Z","dependency_job_id":null,"html_url":"https://github.com/deltatag/enum","commit_stats":null,"previous_names":[],"tags_count":2,"template":null,"template_full_name":null,"purl":"pkg:github/deltatag/enum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltatag%2Fenum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltatag%2Fenum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltatag%2Fenum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltatag%2Fenum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deltatag","download_url":"https://codeload.github.com/deltatag/enum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deltatag%2Fenum/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406428,"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":["database","deltatag","enumeration","php","validation"],"created_at":"2026-01-14T00:00:31.532Z","updated_at":"2026-01-14T00:00:57.399Z","avatar_url":"https://github.com/deltatag.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enumerations for PHP\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/deltatag/enum/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/deltatag/enum/?branch=master)\n[![Total Downloads](https://img.shields.io/packagist/dt/deltatag/enum.svg?style=flat-square)](https://packagist.org/packages/deltatag/enum)\n[![Build Status](https://scrutinizer-ci.com/g/deltatag/enum/badges/build.png?b=master)](https://scrutinizer-ci.com/g/deltatag/enum/build-status/master)\n[![Latest stable version](https://img.shields.io/packagist/v/deltatag/enum.svg?style=flat-square)](https://packagist.org/packages/deltatag/enum)\n[![License](http://img.shields.io/github/license/deltatag/enum.svg?style=flat-square)](https://packagist.org/packages/deltatag/enum)\n\nThe enumeration package provides easy usage of enumerations.\n\nThe enum features are similar to ``SplEnum``, but without installation of an additional PHP package. It provides convenient features to speed up the implementation enumerations to your application.\n\n## Installation\n\n```\ncomposer require deltatag/enum\n```\n\n#### Object methods:\n\n* ``__construct()`` The constructor check if given value is in the enumeration or simply use defined default value. If value not allowed a **EnumValueNotAllowedException** will be thrown.\n* ``__toString()`` You can directly output the enum object or check against value\n* ``getValue()`` Get the current value of the enum object\n* ``isEqual()`` Compare one instance of enum to another\n\n#### Static methods:\n\n* ``getConstants()`` Returns all possible values for enumeration with constant name as key\n* ``getDefault()`` Get default enum value is set. Constant key must be **__default**. If no default value was defined a **EnumDefaultValueNotDefinedException** will be thrown.\n* ``toArray()`` Wrapper for method getConstants()\n* ``isValid()`` Check if value is valid enum value\n\nFor general constant methods you can use the ``ConstantsTrait``.\n\n## Usage\n\nSimply define an enum class of your need and use it for validation.\n\n```php\n// Create new enumeration class which extends Enum base class\nclass Fruits extends Deltatag\\Enum\\Enum\n{\n\t// Default value\n\tconst __default = self::APPLE;\n\t// Enumeration values\n\tconst APPLE = '1';\n\tconst ORANGE = '2';\n\tconst PEAR = '3';\n\tconst BANANA = '4';\n}\n\n// check for constant\n\nFruits::isValid(Fruits::BANANA); // returns true\n\n\n// check for value\n\nFruits::isValid('1'); // returns true\n\nFruits::isValid('Potato') // returns false\n\n// get all values of enumeration\n$enumValues = Fruits::getConstants();\n```\n\nFor object oriented usage you can also use the enum object itself for type-hinting.\n\n```php\n// use enumeration class\n$apple = new Fruits(Fruits::APPLE);\n\nfunction checkMyFruit(Fruits $fruit)\n{\n\tif ($fruit == Fruits::APPLE) {\n\t\techo \"I'm an apple!\";\n\t} else {\n\t\techo \"I'm no apple\";\n\t}\n}\n\ncheckMyFruit($apple); // will output \"I'm an apple!\"\n```\n\nWhen facing other values then strings for constants the comparison must change to the following.\n\n```php\n// use enumeration class\n$apple = new Fruits(Fruits::APPLE);\n\nfunction checkMyFruit(Fruits $fruit)\n{\n    // directly compare enumerations\n\tif (fruit == new Fruits(Fruits::APPLE)) {\n\t\techo \"I'm an apple!\";\n\t} else {\n\t\techo \"I'm no apple\";\n\t}\n}\n```\n\nContributing\n------------\n\nDependencies are managed through composer:\n\n```\n$ composer install\n```\n\nTests can then be run via phpunit:\n\n```\n$ vendor/bin/phpunit\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeltatag%2Fenum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeltatag%2Fenum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeltatag%2Fenum/lists"}