{"id":21215342,"url":"https://github.com/zlikavac32/php-enum-symfony","last_synced_at":"2026-05-18T03:36:26.748Z","repository":{"id":57091525,"uuid":"111571455","full_name":"zlikavac32/php-enum-symfony","owner":"zlikavac32","description":"Symfony support for zlikavac32/php-enum","archived":false,"fork":false,"pushed_at":"2020-04-09T02:15:10.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-07T15:37:41.671Z","etag":null,"topics":["enum","enumeration","php","php-enum","symfony"],"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-21T16:07:18.000Z","updated_at":"2020-04-09T02:15:02.000Z","dependencies_parsed_at":"2022-08-22T20:40:41.188Z","dependency_job_id":null,"html_url":"https://github.com/zlikavac32/php-enum-symfony","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/zlikavac32/php-enum-symfony","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-symfony","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-symfony/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-symfony/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-symfony/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zlikavac32","download_url":"https://codeload.github.com/zlikavac32/php-enum-symfony/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zlikavac32%2Fphp-enum-symfony/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33163799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"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":["enum","enumeration","php","php-enum","symfony"],"created_at":"2024-11-20T21:37:10.810Z","updated_at":"2026-05-18T03:36:26.732Z","avatar_url":"https://github.com/zlikavac32.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Enum Symfony\n\n[![Build Status](https://travis-ci.org/zlikavac32/php-enum-symfony.svg?branch=master)](https://travis-ci.org/zlikavac32/php-enum-symfony) [![Latest Stable Version](https://poser.pugx.org/zlikavac32/php-enum-symfony/v/stable)](https://packagist.org/packages/zlikavac32/php-enum-symfony) [![License](https://poser.pugx.org/zlikavac32/php-enum-symfony/license)](https://packagist.org/packages/zlikavac32/php-enum-symfony)  [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/zlikavac32/php-enum-symfony/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/zlikavac32/php-enum-symfony/?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/8563572691284de08ddf293d810c8ee3)](https://www.codacy.com/app/zlikavac32/php-enum-symfony?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=zlikavac32/php-enum-symfony\u0026amp;utm_campaign=Badge_Grade)\n\nSymfony 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. [Form](#form)\n    1. [Validator](#validator)\n1. [Limitations](#usage)\n\n## Installation\n\nRecommended installation is through Composer.\n\n```\ncomposer require zlikavac32/php-enum-symfony\n```\n\n## Usage\n\nAssumption is that there exists a valid enum `\\YesNoEnum`.\n\n### Form\n\nForm type for enum is provided as `\\Zlikavac32\\SymfonyEnum\\Form\\Type\\EnumType`. There is one required options `enum_class` which must contain enum class FQN.\n\nInternally this extends [\\Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType](https://symfony.com/doc/current/reference/forms/types/choice.html) and populates choices from the defining `enum_class`.\n\nIf any of the `choices` and/or `choice_loader` options is/are passed, an `\\LogicException` will be thrown. Since these fields are overridden internally, passing them from the outside could cloud code's original purpose. Any other option provided by the `\\Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType` can be used.\n\n```php\nuse \\Zlikavac32\\SymfonyEnum\\Form\\Type\\EnumType;\n\nclass FormModel\n{\n    public $answer;\n    \n    // ...\n}\n\n$formModel = new FormModel();\n\n$form = $this-\u003ecreateFormBuilder($formModel)\n    -\u003eadd('answer', EnumType::class, [\n        'enum_class' =\u003e \\YesNoEnum::class\n    ])\n    // ...\n    -\u003egetForm();\n```\n\n### Validator\n\nTwo constraints are provided, `\\Zlikavac32\\SymfonyEnum\\Validator\\Constraints\\ValidEnumElement` and `\\Zlikavac32\\SymfonyEnum\\Validator\\Constraints\\ValidEnumElementName`. Internally, they use `\\Symfony\\Component\\Validator\\Constraints\\Choice`.\n\nRequired constraint argument is `enumClass` which must contain enum class FQN.\n\nIf any of the `choices`, `callback` and/or `strict` options is/are passed, an `\\LogicException` will be thrown. Since these fields are overridden internally, passing them from the outside could cloud code's original purpose. Any other option provided by the `\\Symfony\\Component\\Validator\\Constraints\\Choice` can be used.\n\n- `ValidEnumElement` - accepted values are `null` and any valid enum element from the defined enum class FQN\n- `ValidEnumElementName` - accepted values are `null` and any valid enum element name from the defined enum class FQN\n\nExample for annotation use:\n\n```php\n/**\n * @ValidEnumElement(enumClass=\"\\YesNoEnum\")\n */\n```\n\n## Limitations\n\nDue to [doctrine/common issue #794](https://github.com/doctrine/common/issues/794) with checks for aliased namespaces, validation of form enum element within an array will throw exception in following cases:\n\n- on `Windows` validation does not work at all (due to the anonymous classes)\n- on `Linux` - short enum definition (one that uses `eval()`) does not work so the workaround is to manually instantiate elements\n- on `OSX` - have to check but I'd assume same as `Linux`\n\nFor more details on what's wrong and why, feel free to check related issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzlikavac32%2Fphp-enum-symfony","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzlikavac32%2Fphp-enum-symfony","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzlikavac32%2Fphp-enum-symfony/lists"}