PHPackages                             zlikavac32/php-enum-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. zlikavac32/php-enum-doctrine

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

zlikavac32/php-enum-doctrine
============================

Doctrine PHP enum support

0.6.0(6y ago)1258MITPHPPHP ^7.4CI failing

Since Nov 17Pushed 6y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (8)Used By (0)

PHP Enum Doctrine
=================

[](#php-enum-doctrine)

[![Build Status](https://camo.githubusercontent.com/303c4087d5645a47e4f88793fe41988a74e87efb8329c5b264c9de819ac7e43f/68747470733a2f2f7472617669732d63692e6f72672f7a6c696b6176616333322f7068702d656e756d2d646f637472696e652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zlikavac32/php-enum-doctrine) [![Latest Stable Version](https://camo.githubusercontent.com/cf62680c77b14208cf26ad97dfb247af13a03033aa0294fc4b0e3ebdbcb9e6c3/68747470733a2f2f706f7365722e707567782e6f72672f7a6c696b6176616333322f7068702d656e756d2d646f637472696e652f762f737461626c65)](https://packagist.org/packages/zlikavac32/php-enum-doctrine) [![License](https://camo.githubusercontent.com/7316916f2bcbb552893daae2cfdef7186ea9cb89cb37456bbec0c14f5ad0e708/68747470733a2f2f706f7365722e707567782e6f72672f7a6c696b6176616333322f7068702d656e756d2d646f637472696e652f6c6963656e7365)](https://packagist.org/packages/zlikavac32/php-enum-doctrine) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/4d5b09d66f283e8dd904258b4093e2dff2e5e3b6295de627887bbf9a8b66fc0d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a6c696b6176616333322f7068702d656e756d2d646f637472696e652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zlikavac32/php-enum-doctrine/?branch=master) [![Codacy Badge](https://camo.githubusercontent.com/b3d695698f1660187e0e38ad8c1c8599257b44a4302e67aed2adf003ec56fdd4/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6638666164336531313237333435373362336662623263613035663234626635)](https://www.codacy.com/app/zlikavac32/php-enum-doctrine?utm_source=github.com&utm_medium=referral&utm_content=zlikavac32/php-enum-doctrine&utm_campaign=Badge_Grade)

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

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

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)
    1. [Custom column length](#custom-column-length)
    2. [Custom representation](#custom-representation)
3. [Limitations](#limitations)
4. [Further work](#further-work)

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

[](#installation)

Recommended installation is through Composer.

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

```

Usage
-----

[](#usage)

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

Create a new type that extends `\Zlikavac32\DoctrineEnum\DBAL\Types\EnumType`.

```
use Zlikavac32\DoctrineEnum\DBAL\Types\EnumType;

class YesNoEnumType extends EnumType
{
    // ...
}
```

Next, define `protected function enumClass(): string`. This method should return FQN of the enum class that this type exposes to the Doctrine.

```
protected function enumClass(): string
{
    return \YesNoEnum::class;
}
```

Define Doctrine method `public function getName(): string` that defines type's name.

```
public function getName(): string
{
    return 'enum_yes_no';
}
```

And that's it. Only thing left to do is to register the type using

```
\Doctrine\DBAL\Types\Type::addType('enum_yes_no', \YesNoEnumType::class);
```

You can now use `enum_yes_no` type.

```
/**
 * @Column(type="enum_yes_no", nullable=true)
 * @var \YesNoEnum|null
 */
private $yesNo;
```

For 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).

### Custom column length

[](#custom-column-length)

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

```
protected function columnLength(): int
{
    return 16;
}
```

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

### Custom representation

[](#custom-representation)

By default, name of the enum element is used for it's representation in the database. To change that behaviour, override methods `enumToDatabaseValue()` and `databaseValueToEnum()`.

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

[](#limitations)

This library does not use platform dependent types like `enum` in `MySQL` or custom types in `PostgresSQL`. Instead, `varchar` is used.

Reasons for this are:

- `Doctrine` can not diff enum contents because that's types intrinsic property
- for `PostgresSQL` we can't diff column because type is not in Doctrine control
- column constraints can not be used because they break `ALTER` syntax

If you know how to avoid any of this, please let me know.

Further work
------------

[](#further-work)

Figure out how to overcome issues in [Limitations](#limitations).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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 ~175 days

Recently: every ~111 days

Total

6

Last Release

2223d ago

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

0.3.0PHP ^7.2

0.5.0PHP ^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 (28 commits)")

---

Tags

doctrinedoctrine-enumenumenumerationphpphp-enumenumdoctrineenumerationphp-enumdoctrine-enum

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/zlikavac32-php-enum-doctrine/health.svg)](https://phpackages.com/packages/zlikavac32-php-enum-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.

58523.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)
