Skip to content

A CakePHP plugin providing a collection of UID field types for your applications.

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

josbeir/cakephp-uid

Repository files navigation

CI codecov PHPStan Minimum PHP Version Packagist Downloads License

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.

About

A CakePHP plugin providing a collection of UID field types for your applications.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published

Languages