kiefernwald / doctrine-uuid-generator
Use UUIDv4 as generated id in Doctrine ORM.
Installs: 1 474
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.3
- doctrine/orm: ~2.2,>=2.2.3
- ramsey/uuid: ~2.8
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2025-03-29 00:31:37 UTC
README
Enables support for UUIDv4 as IDs of Doctrine entities.
UUIDv4 creation is based on the awesome ramsey/uuid library. Currently only UUIDs as strings are supported.
Installation
It is recommended to use Composer. You can run the following command to add the library to your requirements in composer.json
:
composer require "kiefernwald/doctrine-uuid-generator=~1.0"
Usage example
You can just use it as CustomIdGenerator. If you are using Annotations, your code should like this:
<?php // ... use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\CustomIdGenerator; /** * Class MyAwesomeEntity * * @Entity * ... */ class MyAwesomeEntity { /** * @var string $uuid * @Column(name="uuid", type="string") * @Id * @GeneratedValue(strategy="CUSTOM") * @CustomIdGenerator(class="Kiefernwald\DoctrineUuid\Doctrine\ORM\UuidGenerator") */ protected $uuid; // ... }