{"id":19818991,"url":"https://github.com/ekvedaras/doctrine-enum","last_synced_at":"2025-02-28T15:31:32.764Z","repository":{"id":56976162,"uuid":"325512278","full_name":"ekvedaras/doctrine-enum","owner":"ekvedaras","description":"🔠   Doctrine integration of ekvedaras/php-enum package","archived":false,"fork":false,"pushed_at":"2020-12-30T14:15:50.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-11T08:14:46.565Z","etag":null,"topics":["doctrine","doctrine-enum","enum","php","php-enum"],"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/ekvedaras.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":"2020-12-30T09:45:13.000Z","updated_at":"2021-06-21T10:54:07.000Z","dependencies_parsed_at":"2022-08-21T07:40:36.553Z","dependency_job_id":null,"html_url":"https://github.com/ekvedaras/doctrine-enum","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekvedaras%2Fdoctrine-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekvedaras%2Fdoctrine-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekvedaras%2Fdoctrine-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekvedaras%2Fdoctrine-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ekvedaras","download_url":"https://codeload.github.com/ekvedaras/doctrine-enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241175283,"owners_count":19922475,"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":["doctrine","doctrine-enum","enum","php","php-enum"],"created_at":"2024-11-12T10:17:30.451Z","updated_at":"2025-02-28T15:31:32.713Z","avatar_url":"https://github.com/ekvedaras.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Doctrine Enum\n\n![Tests](https://github.com/ekvedaras/doctrine-enum/workflows/run-tests/badge.svg)\n[![Code Coverage](https://img.shields.io/codecov/c/gh/ekvedaras/doctrine-enum/main?style=flat)](https://app.codecov.io/gh/ekvedaras/doctrine-enum)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/ekvedaras/doctrine-enum.svg?style=flat)](https://packagist.org/packages/ekvedaras/doctrine-enum)\n[![Total Downloads](https://img.shields.io/packagist/dt/ekvedaras/doctrine-enum.svg?style=flat)](https://packagist.org/packages/ekvedaras/doctrine-enum)\n\n\u003cimg src=\"logo.svg\" width=\"192\" height=\"192\"/\u003e\n\n![Twitter Follow](https://img.shields.io/twitter/follow/ekvedaras?style=plastic)\n\nThis package integrates [ekvedaras/php-enum](https://github.com/ekvedaras/php-enum)\ninto Doctrine by\nproviding [custom enum mapping type](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html#custom-mapping-types).\n\n## Usage\n\n**PaymentStatus.php**\n\n```php\nnamespace App\\Enums;\n\nuse EKvedaras\\Doctrine\\Enum;\n\nclass PaymentStatus extends Enum\n{\n    /**\n     * @return static\n     */\n    final public static function pending(): self\n    {\n        return static::get('pending', 'Payment is pending');\n    }\n\n    /**\n     * @return static\n     */\n    final public static function completed(): self\n    {\n        return static::get('completed', 'Payment has been processed');\n    }\n\n    /**\n     * @return static\n     */\n    final public static function failed(): self\n    {\n        return static::get('failed', 'Payment has failed');\n    }\n}\n```\n\n**UserStatus.php**\n\n```php\nnamespace App\\Enums;\n\nuse EKvedaras\\Doctrine\\Enum;\n\nclass UserStatus extends Enum\n{\n    /**\n     * @return static\n     */\n    final public static function active(): self\n    {\n        return static::get(1, 'User is active');\n    }\n\n    /**\n     * @return static\n     */\n    final public static function banned(): self\n    {\n        return static::get(2, 'User is banned');\n    }\n\n    /**\n     * @return static\n     */\n    final public static function deactivated(): self\n    {\n        return static::get(3, 'User account is deactivated');\n    }\n}\n```\n\n### Casting\n\n**Payment.php**\n\n```php\nuse App\\Enums\\PaymentStatus;\nuse Doctrine\\ORM\\Mapping as ORM;\n\n/**\n * @ORM\\Entity()\n * @ORM\\Table(name=\"payments\")\n */\nclass Payment\n{\n    // ...\n   \n    /**\n     * @var PaymentStatus\n     *\n     * @ORM\\Column(type=PaymentStatus::class)\n     */\n    protected $status;\n\n    // ...\n}\n```\n\n**User.php**\n\n```php\nuse App\\Enums\\UserStatus;\nuse Doctrine\\ORM\\Mapping as ORM;\n\n/**\n * @ORM\\Entity()\n * @ORM\\Table(name=\"users\")\n */\nclass User\n{\n    // ...\n   \n    /**\n     * @var UserStatus\n     *\n     * @ORM\\Column(type=\"user-status\")\n     */\n    protected $status;\n\n    // ...\n}\n```\n\nRegistering enum:\n\n```php\nuse App\\Enums\\PaymentStatus;\nuse App\\Enums\\UserStatus;\nuse EKvedaras\\DoctrineEnum\\EnumType;\n\n// As class name\nEnumType::register(PaymentStatus::class);\nEnumType::register('user-status', UserStatus::class);\n\n// Or multiple at once\nEnumType::register([\n    PaymentStatus::class,\n    'user-status' =\u003e UserStatus::class,\n]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekvedaras%2Fdoctrine-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fekvedaras%2Fdoctrine-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekvedaras%2Fdoctrine-enum/lists"}