bentools/doctrine-ulid

This package is abandoned and no longer maintained. The author suggests using the symfony/uid package instead.

ULID (Universally Unique Lexicographically Sortable Identifier) support for Doctrine IDs

Maintainers

👁 bpolaszek

Package info

github.com/bpolaszek/doctrine-ulid

pkg:composer/bentools/doctrine-ulid

Statistics

Installs: 5 058

Dependents: 2

Suggesters: 0

Stars: 4

Open Issues: 0

1.2 2021-01-23 15:25 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT f4c394f6852cc5316f7619894497debc1d6524f6

  • Beno!t POLASZEK

ormdoctrineuuidulid

This package is auto-updated.

Last update: 2025-09-19 08:04:42 UTC


README

👁 Latest Stable Version
👁 License
👁 Build Status
👁 Coverage
👁 Quality Score
👁 Total Downloads

Doctrine ULID generator

This small library adds support for ULID in Doctrine.

ULIDs act like UUIDs that can be lexicographically sorted. ULIDs also have a smaller footprint (26 ANSI characters vs. 36 for UUIDs);

This package integrates robinvdvleuten/ulid as a CustomIdGenerator.

Important

This repository is no longer maintained. Please use symfony/uid instead.

Installation

composer require bentools/doctrine-ulid

Usage

Use the provided class as a custom ID generator:

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 */
class Foo
{

 /**
 * @var string
 *
 * @ORM\Id()
 * @ORM\GeneratedValue(strategy="CUSTOM")
 * @ORM\CustomIdGenerator(class="\BenTools\ULIDGenerator")
 * @ORM\Column(type="string", length=26)
 */
 private $id;
 
 // ...
 
}

Or use the following trait:

use Doctrine\ORM\Mapping as ORM;
use BenTools\GeneratedULIDTrait;

/**
 * @ORM\Entity()
 */
class Foo
{

 use GeneratedULIDTrait;
 
 // ... 
 
}

If you want to set ULIDs by yourself (this way, they can be generated on the client side), use the EditableULIDTrait which will expose a setId() method:

use Doctrine\ORM\Mapping as ORM;
use BenTools\EditableULIDTrait;

/**
 * @ORM\Entity()
 * @ORM\HasLifecycleCallbacks()
 */
class Foo
{

 use EditableULIDTrait;
 
 // ... 
 
}
  • If setId() is not called, an ULID will be automatically generated on persist.
  • Don't forget to add a @HasLifecycleCallbacks() annotation on top of your entity for this behavior to work properly.

Tests

./vendor/bin/phpunit

License

MIT.