{"id":21215340,"url":"https://github.com/zlikavac32/php-enum-doctrine","last_synced_at":"2025-09-09T01:41:56.423Z","repository":{"id":57091566,"uuid":"111019657","full_name":"zlikavac32/php-enum-doctrine","owner":"zlikavac32","description":"Doctrine support for zlikavac32/php-enum","archived":false,"fork":false,"pushed_at":"2020-04-13T02:10:34.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-16T14:50:38.738Z","etag":null,"topics":["doctrine","doctrine-enum","enum","enumeration","php","php-enum"],"latest_commit_sha":null,"homepage":null,"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/zlikavac32.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-16T20:38:18.000Z","updated_at":"2020-04-13T02:10:18.000Z","dependencies_parsed_at":"2022-08-22T20:41:02.410Z","dependency_job_id":null,"html_url":"https://github.com/zlikavac32/php-enum-doctrine","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/zlikavac32/php-enum-doctrine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-doctrine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-doctrine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-doctrine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-doctrine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zlikavac32","download_url":"https://codeload.github.com/zlikavac32/php-enum-doctrine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-doctrine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274232034,"owners_count":25245856,"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","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["doctrine","doctrine-enum","enum","enumeration","php","php-enum"],"created_at":"2024-11-20T21:37:10.110Z","updated_at":"2025-09-09T01:41:56.397Z","avatar_url":"https://github.com/zlikavac32.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Enum Doctrine\n\n[![Build Status](https://travis-ci.org/zlikavac32/php-enum-doctrine.svg?branch=master)](https://travis-ci.org/zlikavac32/php-enum-doctrine) [![Latest Stable Version](https://poser.pugx.org/zlikavac32/php-enum-doctrine/v/stable)](https://packagist.org/packages/zlikavac32/php-enum-doctrine) [![License](https://poser.pugx.org/zlikavac32/php-enum-doctrine/license)](https://packagist.org/packages/zlikavac32/php-enum-doctrine) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/zlikavac32/php-enum-doctrine/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/zlikavac32/php-enum-doctrine/?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f8fad3e112734573b3fbb2ca05f24bf5)](https://www.codacy.com/app/zlikavac32/php-enum-doctrine?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=zlikavac32/php-enum-doctrine\u0026amp;utm_campaign=Badge_Grade)\n\nDoctrine support for [zlikavac32/php-enum](https://github.com/zlikavac32/php-enum).\n\n## Table of contents\n\n1. [Installation](#installation)\n1. [Usage](#usage)\n    1. [Custom column length](#custom-column-length)\n    1. [Custom representation](#custom-representation)\n1. [Limitations](#limitations)\n1. [Further work](#further-work)\n\n## Installation\n\nRecommended installation is through Composer.\n\n```\ncomposer require zlikavac32/php-enum-doctrine\n```\n\n## Usage\n\nAssumption is that there exists a valid enum `\\YesNoEnum`.\n\nCreate a new type that extends `\\Zlikavac32\\DoctrineEnum\\DBAL\\Types\\EnumType`.\n\n```php\nuse Zlikavac32\\DoctrineEnum\\DBAL\\Types\\EnumType;\n\nclass YesNoEnumType extends EnumType \n{\n    // ...\n}\n```\n\nNext, define `protected function enumClass(): string`. This method should return FQN of the enum class that this type exposes to the Doctrine.\n\n```php\nprotected function enumClass(): string\n{\n    return \\YesNoEnum::class;\n}\n```\n\nDefine Doctrine method `public function getName(): string` that defines type's name.\n\n```php\npublic function getName(): string\n{\n    return 'enum_yes_no';\n}\n```\n\nAnd that's it. Only thing left to do is to register the type using \n\n\n```php\n\\Doctrine\\DBAL\\Types\\Type::addType('enum_yes_no', \\YesNoEnumType::class);\n```\n\nYou can now use `enum_yes_no` type.\n\n```php\n/**\n * @Column(type=\"enum_yes_no\", nullable=true)\n * @var \\YesNoEnum|null\n */\nprivate $yesNo;\n```\n\nFor more info on the custom Doctrine mapping types, check [official documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types).\n\n### Custom column length\n\nInternally this library uses `varchar` type with the maximum length of `32`. If you want to fit the length to your own needs, just override method `protected function columnLength(): int`.\n\n```php\nprotected function columnLength(): int\n{\n    return 16;\n}\n```\n\nNote that on types first usage, all enum elements names are checked against specified column length. If a name longer than maximum length is detected, a `\\LogicException` is thrown.\n\n### Custom representation\n\nBy default, name of the enum element is used for it's representation in the database. To change that behaviour, override methods `enumToDatabaseValue()` and `databaseValueToEnum()`.\n\n## Limitations\n\nThis library does not use platform dependent types like `enum` in `MySQL` or custom types in `PostgresSQL`. Instead, `varchar` is used.\n\nReasons for this are:\n\n- `Doctrine` can not diff enum contents because that's types intrinsic property\n- for `PostgresSQL` we can't diff column because type is not in Doctrine control\n- column constraints can not be used because they break `ALTER` syntax\n\nIf you know how to avoid any of this, please let me know.\n\n## Further work\n\nFigure out how to overcome issues in [Limitations](#limitations).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzlikavac32%2Fphp-enum-doctrine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzlikavac32%2Fphp-enum-doctrine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzlikavac32%2Fphp-enum-doctrine/lists"}