Doctrine Helper

← Doctrine Helper

Ashterix

docs: Doctrine section with Doctrine Behaviors and Doctrine Helper (uk + en)

en/docs/doctrine/doctrine-helper/README.md new file +52 −0

Doctrine Helper

<include>(docs/doctrine/doctrine-helper/.info.md)

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

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.

en/docs/doctrine/doctrine-helper/.info.md new file +18 −0

Version Downloads Stars

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