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

1.02 2025-08-11 08:49 UTC

This package is auto-updated.

Last update: 2025-08-11 14:41:21 UTC


README

CI PHPStan Minimum PHP Version Packagist Downloads

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) or BINARY(16) or CHAR(36):
  • FOR ULID: use column type BINARY(16) or CHAR(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.