Doctrine Helper
composer require ufo-tech/doctrine-helper
- PHP 8.3+
- Built on Doctrine ORM 2.12+ · 3, DBAL 3.2+ · 4
- Type PHP library
- Category Doctrine
- License MIT
A set of ready-made traits, interfaces and classes for Doctrine that take the routine out of describing entities: primary keys (auto-increment, UUID, uniqid) and PHP enums as the MySQL ENUM type.
It is a plain library, not a Symfony bundle: it registers nothing in the container and has no configuration of its own. Traits are added to an entity with use; the enum type is registered in the Doctrine DBAL settings.
What is inside
| Class | Purpose |
|---|---|
Ufo\DoctrineHelper\Traits\AutoIncrementIdTrait |
Auto-increment integer id |
Ufo\DoctrineHelper\Traits\UuidIdTrait |
id is a UUID v7 generated in code |
Ufo\DoctrineHelper\Traits\UniqueIdTrait |
id is a 13-character uniqid() string |
Ufo\DoctrineHelper\Traits\UniqueUuidIdTrait |
Deprecated, use UuidIdTrait instead |
Ufo\DoctrineHelper\Interfaces\IHaveUniqueUuid |
Contract of an entity with a string id |
Ufo\DoctrineHelper\Interfaces\IHaveAutoincrementId |
Contract of an entity with an integer id |
Ufo\DoctrineHelper\Utils\Uuid |
Generates UUID v7 and deterministic UUID v3 |
Ufo\DoctrineHelper\DBAL\AbstractEnumType |
Base DBAL type for a PHP backed enum → ENUM(...) |
Example
use Doctrine\ORM\Mapping as ORM;
use Ufo\DoctrineHelper\Interfaces\IHaveUniqueUuid;
use Ufo\DoctrineHelper\Traits\UuidIdTrait;
#[ORM\Entity]
class Order implements IHaveUniqueUuid
{
use UuidIdTrait; // #[ORM\Id], string(36), unique, getId(): string
public function __construct()
{
$this->generateUniqueId(); // UUID v7
}
}
Sections
- Entity identifiers — primary key traits, interfaces,
Uuid. - PHP enum as ENUM —
AbstractEnumType, type registration, limitations. - Changelog
- Known issues
This documentation describes version 1.1.0 (2025-06-09). The doctrine/orm and doctrine/dbal dependencies are declared in composer.json only since 1.1.0; before that the library required only ramsey/uuid.