robinvdvleuten / ulid
Universally Unique Lexicographically Sortable Identifier (ULID) implementation for PHP.
Installs: 2 214 312
Dependents: 28
Suggesters: 1
Security: 0
Stars: 442
Watchers: 7
Forks: 34
Open Issues: 5
Requires
- php: ^7.2|^8.0
Requires (Dev)
- phpbench/phpbench: ^1.0.0-alpha3
- phpunit/phpunit: ^8.5
- symfony/phpunit-bridge: ^5.1
README
A PHP port of ulid/javascript with some minor improvements.
Installation
You can install the package via Composer.
composer require robinvdvleuten/ulid
Usage
use Ulid\Ulid; $ulid = Ulid::generate(); echo (string) $ulid; // 01B8KYR6G8BC61CE8R6K2T16HY // Or if you prefer a lowercased output $ulid = Ulid::generate(true); echo (string) $ulid; // 01b8kyr6g8bc61ce8r6k2t16hy // If you need the timestamp from an ULID instance $ulid = Ulid::generate(); echo $ulid->toTimestamp(); // 1561622862 // You can also generate a ULID for a specific UNIX-time in milliseconds $ulid = Ulid::fromTimestamp(1593048767015); // or with a lower cased output: $ulid = Ulid::fromTimestamp(1593048767015, true); echo (string) $ulid; // 01EBMHP6H7TT1Q4B7CA018K5MQ
Testing
composer test
Changelog
Please see the GitHub "Releases" page for more information on what has changed recently.
Credits
As it's just a simple port of JavaScript to PHP code. All credits should go to the original ULID specs.
License
The MIT License (MIT). Please see License File for more information.