PHPackages                             nepada/consistence-doctrine - 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. nepada/consistence-doctrine

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

nepada/consistence-doctrine
===========================

Consistence Enum types for Doctrine.

v1.1.1(3y ago)214.3k↓26.7%BSD-3-ClausePHPPHP &gt;=7.4.0 &lt;8.2

Since Mar 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/nepada/consistence-doctrine)[ Packagist](https://packagist.org/packages/nepada/consistence-doctrine)[ RSS](/packages/nepada-consistence-doctrine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (13)Versions (4)Used By (0)

Consistence Enum Doctrine types
===============================

[](#consistence-enum-doctrine-types)

[![Build Status](https://github.com/nepada/consistence-doctrine/workflows/CI/badge.svg)](https://github.com/nepada/consistence-doctrine/actions?query=workflow%3ACI+branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/bc552867268f50042e5f9206488bbeb6ac4d229a2b8d039cfd3cde1929c91762/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e65706164612f636f6e73697374656e63652d646f637472696e652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/nepada/consistence-doctrine?branch=master)[![Downloads this Month](https://camo.githubusercontent.com/c9bca694cb80468e98b88d9f7ae3987306c0616105a853d0c0e2f814be3fb9df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e65706164612f636f6e73697374656e63652d646f637472696e652e737667)](https://packagist.org/packages/nepada/consistence-doctrine)[![Latest stable](https://camo.githubusercontent.com/8c42f5ae83480d040bb7df403bb7395b31351a7fb2785c9e80727e3e93cc11e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65706164612f636f6e73697374656e63652d646f637472696e652e737667)](https://packagist.org/packages/nepada/consistence-doctrine)

Package abandoned
-----------------

[](#package-abandoned)

**This package is considered obsolete and abandoned.** Since PHP 8.1 introduced native enum support, there is no need for user-land implementation of enums, neither their custom integration into Doctrine.

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

[](#installation)

Via Composer:

```
$ composer require nepada/consistence-doctrine
```

Usage
-----

[](#usage)

### Define Doctrine type for the enum

[](#define-doctrine-type-for-the-enum)

```
/**
 * @phpstan-extends \Nepada\ConsistenceDoctrine\StringEnumType
 */
class FooEnumType extends \Nepada\ConsistenceDoctrine\StringEnumType
{

    protected function getEnumClassName(): string
    {
        return \FooEnum::class;
    }

}
```

You can choose to inherit from `StringEnumType`, `IntegerEnumType`, `FloatEnumType` or `BooleanEnumType` depending on the enum values.

### Register the created type in Doctrine

[](#register-the-created-type-in-doctrine)

```
\Doctrine\DBAL\Types\Type::addType(\FooEnum::class, \FooEnumType::class);
```

In Nette with [nettrine/dbal](https://github.com/nettrine/dbal) integration, you can register the types in your configuration:

```
dbal:
    connection:
        types:
            FooEnum: FooEnumType
```

### Use the type in entity

[](#use-the-type-in-entity)

```
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class SomeEntity
{

    /** @ORM\Column(type=\FooEnum::class, nullable=false) */
    private \FooEnum $foo;

    // ...

}
```

### Use enum in query builder

[](#use-enum-in-query-builder)

```
$result = $repository->createQueryBuilder('bar')
    ->select('bar.foo') // FooEnum instances are created during hydratation
    ->where('bar.foo = :fooEnum')
    ->setParameter('fooEnum', \FooEnum::get(\FooEnum::VALUE), \FooEnum::class) // enum instance gets serialized
    ->getQuery()
    ->setMaxResults(1)
    ->getSingleResult();
```

### PHPStan support (via `phpstan/phpstan-doctrine`)

[](#phpstan-support-via-phpstanphpstan-doctrine)

The abstract enum type classes are anotated as PHPStan generics and define proper typehints for their `convert*` methods. This means you can teach PHPStan your custom enum types via `ReflectionDescriptor`:

```
services:
    -
        factory: PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor(FooEnumType)
        tags: [phpstan.doctrine.typeDescriptor]
```

Differences from the official `consistence/consistence-doctrine`
----------------------------------------------------------------

[](#differences-from-the-official-consistenceconsistence-doctrine)

The official integration `consistence/consistence-doctrine` uses postload entity event to convert data stored in database to enum instances.

The main advantage of that approach is that you don't need to create and register new doctrine type for every enum.

The disadvantages are:

- You can't use native property typehints for entity enum attributes.
- When you're not hydrating entites, you will get enum values instead of enum instances.
- There is no easy way how to make PHPStan understand and check doctrine and PHP types of your enum fields.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 57.8% 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 ~433 days

Total

3

Last Release

1374d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.4.0

v1.1.0PHP &gt;=7.4.0 &lt;8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b4780fe328102c4572737db639653c29d3081d1d3e051467f00d7f09a776399?d=identicon)[xificurk](/maintainers/xificurk)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (63 commits)")[![xificurk](https://avatars.githubusercontent.com/u/117465?v=4)](https://github.com/xificurk "xificurk (46 commits)")

---

Tags

enumdoctrineconsistence

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nepada-consistence-doctrine/health.svg)

```
[![Health](https://phpackages.com/badges/nepada-consistence-doctrine/health.svg)](https://phpackages.com/packages/nepada-consistence-doctrine)
```

###  Alternatives

[fresh/doctrine-enum-bundle

Provides support of ENUM type for Doctrine2 in Symfony applications.

4636.8M12](/packages/fresh-doctrine-enum-bundle)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[api-platform/schema-generator

Various tools to generate a data model based on Schema.org vocables

4714.2M7](/packages/api-platform-schema-generator)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)

PHPackages © 2026

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