PHPackages                             precision-soft/doctrine-type - 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. precision-soft/doctrine-type

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

precision-soft/doctrine-type
============================

doctrine custom types

v3.4.5(2w ago)07.9k↓54.1%1MITPHPPHP &gt;=8.2

Since Sep 17Pushed 2w agoCompare

[ Source](https://github.com/precision-soft/doctrine-type)[ Packagist](https://packagist.org/packages/precision-soft/doctrine-type)[ Docs](https://github.com/precision-soft/doctrine-type)[ RSS](/packages/precision-soft-doctrine-type/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (16)Versions (27)Used By (1)

Doctrine Type
=============

[](#doctrine-type)

[![PHP >= 8.2](https://camo.githubusercontent.com/8f0af9c5395ae4ef8ba7a7ad65fa61c44927ea9c3eb3be91a13c678254f29bd4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d383839324246)](https://www.php.net/)[![PHPStan Level 8](https://camo.githubusercontent.com/44dc5f71fec76653887c975fe3db546a82ff603d094798eb6414a38369db1f44/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d6c6576656c253230382d627269676874677265656e)](https://phpstan.org/)[![Code Style PER-CS2.0](https://camo.githubusercontent.com/5cbab3b5c635536159b4d0a5ef49ebc70fcc20757f82d5f83bc251d872914301/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d5045522d2d4353322e302d626c7565)](https://www.php-fig.org/per/coding-style/)[![License MIT](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

Custom Doctrine DBAL types for MySQL `ENUM`, `SET`, `DATETIME` (with `ON UPDATE`), and `TINYINT` columns.

This library provides abstract base classes you can extend to define your own Doctrine types backed by PHP enums, as well as ready-to-use types for `DATETIME` and `TINYINT`.

Supports Doctrine DBAL 4, PHP 8.2+.

**You may fork and modify it as you wish.**

Any suggestions are welcomed.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Doctrine DBAL 4

What It Does
------------

[](#what-it-does)

Doctrine DBAL does not ship native support for MySQL-specific column types such as `ENUM`, `SET`, or `TINYINT`. This library fills that gap by providing:

- **AbstractEnumType** -- extend it to map a PHP enum to a MySQL `ENUM` column. On non-MySQL platforms it falls back to the platform's string type.
- **AbstractSetType** -- extend it to map a PHP enum to a MySQL `SET` column. Values are stored as a comma-separated string and hydrated as arrays of enum cases.
- **DateTimeType** -- extends the default Doctrine `DateTimeType` and adds support for `ON UPDATE CURRENT_TIMESTAMP` on MySQL columns.
- **TinyintType** -- maps a MySQL `TINYINT` column (signed or unsigned) with range validation.

All types use project-specific exceptions so you can catch type-related errors without catching unrelated exceptions:

- `PrecisionSoft\Doctrine\Type\Exception\Exception` -- base exception for all type errors (e.g. unsupported platform).
- `PrecisionSoft\Doctrine\Type\Exception\InvalidTypeValueException` -- thrown when a value fails validation (wrong type, out of range, invalid enum case).

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

[](#installation)

```
composer require precision-soft/doctrine-type
```

Types
-----

[](#types)

### Enum

[](#enum)

Extend `AbstractEnumType` and point it at a PHP enum (backed or unit).

```
