phpgt / ulid
Unique, lexicographically sortable identifiers.
Fund package maintenance!
PhpGt
Installs: 1 528
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 2
Requires
- php: >=8.0
Requires (Dev)
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.3
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-10-30 02:26:48 UTC
README
Create a new Ulid()
anywhere in your application, and you have a stringable object that can be used as the primary key in a database. Ulid strings look something like 01G2J6MYN0PGC5Q21W9C
or can be prefixed with a type like CUSTOMER_01G2J6MYN0PGC5Q21W9C
. They are cryptographically pseudo-random, and sort so that newer Ulids compare "greater than" older Ulids.
This solves the problems exposed with working with auto-incrementing integer primary keys, which are predictable and difficult to work with in distributed databases.
Example usage:
use Gt\Ulid\Ulid; $exampleDataSource->create(new Person( new Ulid("pet"), name: "Cody", age: 5, ));