PHPackages                             zlikavac32/php-enum-symfony - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zlikavac32/php-enum-symfony

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zlikavac32/php-enum-symfony
===========================

Symfony PHP enum support

0.6.0(6y ago)186MITPHPPHP &gt;=7.4

Since Nov 21Pushed 6y ago1 watchersCompare

[ Source](https://github.com/zlikavac32/php-enum-symfony)[ Packagist](https://packagist.org/packages/zlikavac32/php-enum-symfony)[ RSS](/packages/zlikavac32-php-enum-symfony/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (7)Used By (0)

PHP Enum Symfony
================

[](#php-enum-symfony)

[![Build Status](https://camo.githubusercontent.com/06be958150a87b3d5a75eb24590f4dc42afab17b71eba03e4055aa8577ef603e/68747470733a2f2f7472617669732d63692e6f72672f7a6c696b6176616333322f7068702d656e756d2d73796d666f6e792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zlikavac32/php-enum-symfony) [![Latest Stable Version](https://camo.githubusercontent.com/a4e98aac40800ce65aa916ff53eba48b5299c31cc2569edcba8ebb9ec68c0774/68747470733a2f2f706f7365722e707567782e6f72672f7a6c696b6176616333322f7068702d656e756d2d73796d666f6e792f762f737461626c65)](https://packagist.org/packages/zlikavac32/php-enum-symfony) [![License](https://camo.githubusercontent.com/ac51482edb77b4f1f4cdf6c96e446689d055b2b8733843c78b9c1caa527f964a/68747470733a2f2f706f7365722e707567782e6f72672f7a6c696b6176616333322f7068702d656e756d2d73796d666f6e792f6c6963656e7365)](https://packagist.org/packages/zlikavac32/php-enum-symfony) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/fe0d3e5295843b6cca1d4dc0660b110c6936a199eb82042b8360932ec6073f50/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a6c696b6176616333322f7068702d656e756d2d73796d666f6e792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zlikavac32/php-enum-symfony/?branch=master) [![Codacy Badge](https://camo.githubusercontent.com/30cb44091fe3c26a41f87cf6a23908fffbef5d8a8e0a3a3296d2e530e9574345/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3835363335373236393132383464653038646466323933643831306338656533)](https://www.codacy.com/app/zlikavac32/php-enum-symfony?utm_source=github.com&utm_medium=referral&utm_content=zlikavac32/php-enum-symfony&utm_campaign=Badge_Grade)

Symfony support for [zlikavac32/php-enum](https://github.com/zlikavac32/php-enum).

Table of contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)
    1. [Form](#form)
    2. [Validator](#validator)
3. [Limitations](#usage)

Installation
------------

[](#installation)

Recommended installation is through Composer.

```
composer require zlikavac32/php-enum-symfony

```

Usage
-----

[](#usage)

Assumption is that there exists a valid enum `\YesNoEnum`.

### Form

[](#form)

Form type for enum is provided as `\Zlikavac32\SymfonyEnum\Form\Type\EnumType`. There is one required options `enum_class` which must contain enum class FQN.

Internally 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`.

If 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.

```
use \Zlikavac32\SymfonyEnum\Form\Type\EnumType;

class FormModel
{
    public $answer;

    // ...
}

$formModel = new FormModel();

$form = $this->createFormBuilder($formModel)
    ->add('answer', EnumType::class, [
        'enum_class' => \YesNoEnum::class
    ])
    // ...
    ->getForm();
```

### Validator

[](#validator)

Two constraints are provided, `\Zlikavac32\SymfonyEnum\Validator\Constraints\ValidEnumElement` and `\Zlikavac32\SymfonyEnum\Validator\Constraints\ValidEnumElementName`. Internally, they use `\Symfony\Component\Validator\Constraints\Choice`.

Required constraint argument is `enumClass` which must contain enum class FQN.

If 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.

- `ValidEnumElement` - accepted values are `null` and any valid enum element from the defined enum class FQN
- `ValidEnumElementName` - accepted values are `null` and any valid enum element name from the defined enum class FQN

Example for annotation use:

```
/**
 * @ValidEnumElement(enumClass="\YesNoEnum")
 */
```

Limitations
-----------

[](#limitations)

Due 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:

- on `Windows` validation does not work at all (due to the anonymous classes)
- on `Linux` - short enum definition (one that uses `eval()`) does not work so the workaround is to manually instantiate elements
- on `OSX` - have to check but I'd assume same as `Linux`

For more details on what's wrong and why, feel free to check related issue.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~173 days

Recently: every ~201 days

Total

6

Last Release

2221d ago

PHP version history (3 changes)0.1.0PHP &gt;=7.1

0.4.0PHP &gt;=7.2

0.6.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b47ffc503d7c4536136bc08ed1185682bec5789108bd7a2cf7edfee98994dfef?d=identicon)[zlikavac32](/maintainers/zlikavac32)

---

Top Contributors

[![zlikavac32](https://avatars.githubusercontent.com/u/1078270?v=4)](https://github.com/zlikavac32 "zlikavac32 (23 commits)")

---

Tags

enumenumerationphpphp-enumsymfonysymfonyenumenumerationphp-enumsymfony-enum

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zlikavac32-php-enum-symfony/health.svg)

```
[![Health](https://phpackages.com/badges/zlikavac32-php-enum-symfony/health.svg)](https://phpackages.com/packages/zlikavac32-php-enum-symfony)
```

###  Alternatives

[craue/config-bundle

Database-stored settings made available via a service for your Symfony project.

1771.0M4](/packages/craue-config-bundle)[jbtronics/settings-bundle

A symfony bundle to easily create typesafe, user-configurable settings for symfony applications

9546.7k2](/packages/jbtronics-settings-bundle)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[symfony/ux-cropperjs

Cropper.js integration for Symfony

19280.3k3](/packages/symfony-ux-cropperjs)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)[zlikavac32/php-enum

Better PHP enum support

225.6k5](/packages/zlikavac32-php-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
