josbeir / cakephp-uid
CakePHP plugin that provides various UID types for the ORM
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=8.2
- cakephp/cakephp: ^5.1
- symfony/uid: ^7.3
Requires (Dev)
- cakephp/cakephp-codesniffer: ^5.2
- cakephp/plugin-installer: ^2
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.5 || ^11.1 || ^12.0
README
CakePHP UID Plugin
A CakePHP plugin providing a collection of UID field types for your applications.
You can follow ongoing discussion about native UID support on the official CakePHP issue tracker here. This plugin provides a solution until more convenient support is available in CakePHP core.
Features
- UUIDv4 field type
- UUIDv6 field type
- UUIDv7 field type
- ULID field type
Easily add modern, sortable unique identifiers to your CakePHP models.
Installation
Install via Composer:
composer require josbeir/cakephp-uid
Usage
Before using the UID field types in your schema, you need to map them using TypeFactory::map
in your application bootstrap or plugin initialization:
If you want to use these types instead of CakePHP's native ones, you need to override the original types as shown below. CakePHP will handle the rest based on your database field settings.
- For UUID: use column type
UUID
(when supported by your db) orBINARY(16)
orCHAR(36)
: - FOR ULID: use column type
BINARY(16)
orCHAR(26)
: - Remember that a UUID/BINARY is prefererd for performance reasons.
TypeFactory::map('binaryuuid', BinaryUuidV7Type::class); // Uses UUID V7 TypeFactory::map('binaryuuid', BinaryUlidType::class); // Uses ULID
Other possibilities:
TypeFactory::map('uuidv4', UuidV4Type::class); TypeFactory::map('uuidv6', UuidV6Type::class); TypeFactory::map('uuidv7', UuidV7Type::class); TypeFactory::map('ulid', UlidType::class); TypeFactory::map('binaryuuidv4', BinaryUuidV4Type::class); TypeFactory::map('binaryuuidv6', BinaryUuidV6Type::class); TypeFactory::map('binaryuuidv7', BinaryUuidV7Type::class); TypeFactory::map('binaryulid', BinaryUlidType::class);
Underlying Library
This plugin utilizes the Symfony UID component to generate, validate, and convert UIDs. Refer to the Symfony documentation for advanced usage and interoperability details.
License
MIT
Contributing
Pull requests are welcome. For major changes, please open an issue first.