PHPackages                             vkollin/doctrine-backed-enum-fields-bundle - 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. [Database &amp; ORM](/categories/database)
4. /
5. vkollin/doctrine-backed-enum-fields-bundle

ActiveLibrary[Database &amp; ORM](/categories/database)

vkollin/doctrine-backed-enum-fields-bundle
==========================================

Provides truly support for backed enums in doctrine by generating enum fields, not string fields.

1.4.1(2y ago)024.8k↓35.2%2[1 PRs](https://github.com/vkollin/doctrine-backed-enum-fields-bundle/pulls)MITPHPPHP &gt;=8.1

Since Jul 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/vkollin/doctrine-backed-enum-fields-bundle)[ Packagist](https://packagist.org/packages/vkollin/doctrine-backed-enum-fields-bundle)[ RSS](/packages/vkollin-doctrine-backed-enum-fields-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (5)Versions (8)Used By (0)

Symfony Doctrine Enum Fields Bundle
===================================

[](#symfony-doctrine-enum-fields-bundle)

This library provides support to [PHP Enums](https://wiki.php.net/rfc/enumerations), introduced in PHP 8.1, within your Doctrine entities and will generate enum fields for you.

Doctrine introduced [kinda enum support](https://www.doctrine-project.org/2022/01/11/orm-2.11.html), but this will give you just string fields.

Thanks
------

[](#thanks)

This project was forked from [bpolaszek/doctrine-native-enums](https://github.com/bpolaszek/doctrine-native-enums) by [Beno!t POLASZEK](https://github.com/bpolaszek) and heavily inspired by [this blog post](https://knplabs.com/en/blog/how-to-map-a-php-enum-with-doctrine-in-a-symfony-project)

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

[](#installation)

```
composer require vkollin/doctrine-backed-enum-fields-bundle
```

Usage
-----

[](#usage)

This library only works with [Backed enums](https://wiki.php.net/rfc/enumerations#backed_enums).

### In a Symfony project

[](#in-a-symfony-project)

#### 1. Declare the bundle.

[](#1-declare-the-bundle)

```
// config/bundles.php

return [
    // ...
    VKollin\Doctrine\BackedEnumFields\Bundle\DoctrineBackedEnumFieldsBundle::class => ['all' => true],
];
```

#### 2. Register enums in your configuration.

[](#2-register-enums-in-your-configuration)

```
# config/packages/doctrine_backed_enum_fields.yaml

doctrine_backed_enum_fields:
  enum_types:
    App\Entity\StatusEnum: ~
    #App\Entity\StatusEnum: status # Alternatively, if you want your type to be named "status"
```

#### 3. Use them in your entities.

[](#3-use-them-in-your-entities)

```
declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
final class Book
{
    #[
        ORM\Id,
        ORM\Column(unique: true),
        ORM\GeneratedValue(strategy: 'AUTO'),
    ]
    public int $id;

    #[ORM\Column]
    public string $name;

    #[ORM\Column(type: StatusEnum::class)]
    public StatusEnum $status;
}
```

### Enums in your key

[](#enums-in-your-key)

You need to use a custom id generator to use enums as your key. It is also required to set the GeneratedValue strategy to CUSTOM. Otherwise the custom id generator will not be used. Nothing will be generated here though.

```
#[ORM\Column(name: 'type', type: StatusEnum::class, nullable: false)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(EnumIdGenerator::class)]
#[ORM\Id]
private StatusEnum $status,
```

Then you also need to tag the custom id generator as a doctrine id\_generator in your services.yaml

```
    VKollin\Doctrine\BackedEnumFields\IdGenerator\EnumIdGenerator:
        class: VKollin\Doctrine\BackedEnumFields\IdGenerator\EnumIdGenerator
        tags: [ 'doctrine.id_generator' ]
```

### In other projects using Doctrine

[](#in-other-projects-using-doctrine)

```
use App\Entity\StatusEnum;
use BenTools\Doctrine\NativeEnums\Type\NativeEnum;
use Doctrine\DBAL\Types\Type;

NativeEnum::registerEnumType(StatusEnum::class);
// NativeEnum::registerEnumType('status', StatusEnum::class); // Alternatively, if you want your type to be named "status"
```

License
-------

[](#license)

MIT.

*Ceterum censeo Doctrinam esse delendam*

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 69.2% 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 ~110 days

Recently: every ~141 days

Total

7

Last Release

792d ago

Major Versions

0.0.5 → 1.4.02024-05-02

### Community

Maintainers

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

---

Top Contributors

[![vkollin](https://avatars.githubusercontent.com/u/5981580?v=4)](https://github.com/vkollin "vkollin (9 commits)")[![gempir](https://avatars.githubusercontent.com/u/9765622?v=4)](https://github.com/gempir "gempir (3 commits)")[![Schluepfer](https://avatars.githubusercontent.com/u/18718586?v=4)](https://github.com/Schluepfer "Schluepfer (1 commits)")

### Embed Badge

![Health badge](/badges/vkollin-doctrine-backed-enum-fields-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/vkollin-doctrine-backed-enum-fields-bundle/health.svg)](https://phpackages.com/packages/vkollin-doctrine-backed-enum-fields-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)

PHPackages © 2026

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