Go to file
Anton Smirnov d9f701acb0 Test on 32 bit image 2023-09-04 23:22:06 +03:00
docs Add 'per millisecond' 2023-07-19 09:24:20 +03:00
src Consistently use enums 2023-08-04 22:50:23 +03:00
tests Test with the default SystemClock 2023-08-04 22:58:10 +03:00
.gitattributes Docs stub 2023-06-28 20:41:23 +03:00
.gitignore Parser doc 2023-06-29 22:35:45 +03:00
.gitlab-ci.yml Test on 32 bit image 2023-09-04 23:22:06 +03:00
.readthedocs.yaml readthedocs.yaml -> .readthedocs.yaml 2023-07-03 19:39:19 +03:00
CHANGELOG.md Changelog for 1.2.1 2023-08-04 22:27:37 +03:00
LICENSE.md License 2023-07-05 03:16:59 +03:00
README.md Documentation is done 2023-07-12 23:53:44 +03:00
composer.json Explain 32 bit 2023-07-08 03:40:39 +03:00
phpcs.xml Make classes readonly 2023-06-26 21:12:50 +03:00
phpunit.dist.xml Upgrade phpunit.xml 2023-06-02 21:22:10 +03:00
psalm.xml Update to level 5 2023-07-07 21:11:28 +03:00

README.md

PHP UUID Library

Packagist PHP License Gitlab pipeline status Codecov

UUID and ULID classes for PHP.

Usage

<?php

use Arokettu\Uuid\UlidFactory;
use Arokettu\Uuid\UlidParser;
use Arokettu\Uuid\UuidFactory;
use Arokettu\Uuid\UuidNamespaces;
use Arokettu\Uuid\UuidParser;

// create UUIDs versions 3, 4, 5, 7, 8 and ULIDs
$uuid4 = UuidFactory::v4(); // example: 5c24b036-6202-419f-a1f3-48cbe6ebf17a
$uuid5 = UuidFactory::v5(UuidNamespaces::url(), 'http://example.com/'); // 0a300ee9-f9e4-5697-a51a-efc7fafaba67
$uuid7 = UuidFactory::v7(); // example: 01892370-4c48-70cf-9cb9-96784308f504
$ulid  = UlidFactory::ulid(); // example: 01H4HQC4G1C1606J19358PWESA

// get data like timestamps on UUIDs versions 1, 2, 6, 7 and ULIDs
$uuid7->getDateTime(); // 2023-07-05 00:25:09.448 +00:00

// parse existing UUID or ULID
$uuid  = UuidParser::fromString('01892370-4c48-70cf-9cb9-96784308f504'); // == $uuid7
$ulid2 = UlidParser::fromString('01H4HQC4G1C1606J19358PWESA'); // == $uuid

// possible killer features
// UUIDv1 to UUIDv6 conversion (and vice versa)
UuidParser::fromString('e982dc4e-1acc-11ee-be56-0242ac120002')
    ->toUuidV6(); // 1ee1acce-982d-6c4e-be56-0242ac120002
// ULID to UUIDv7 conversion (lossy but predictable)
UlidParser::fromString('01H4HQC4G1C1606J19358PWESA')
    ->toUuidV7(lossy: true); // 01892376-1201-704c-8348-2919516e3b2a

Installation

composer require arokettu/uuid
  • GMP extension is strongly recommended on 32-bit systems.

Documentation

Read full documentation here: https://sandfox.dev/php/uuid.html

Also on Read the Docs: https://arokettu-uuid.readthedocs.io/

Support

Please file issues on our main repo at GitLab: https://gitlab.com/sandfox/php-uuid/-/issues

Feel free to ask any questions in our room on Gitter: https://gitter.im/arokettu/community

License

The library is available as open source under the terms of the MIT License.