Skip to content

Commit

Permalink
Draft -> RFC 9562 (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
oittaa authored Jul 10, 2024
1 parent b68702a commit a0efdb6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# uuid-php

A small PHP class for generating [RFC 4122][RFC 4122] version 3, 4, and 5 universally unique identifiers (UUID). Additionally supports [draft][draft] versions 6, 7, and 8.
A small PHP class for generating [RFC 9562][RFC 9562] universally unique identifiers (UUID) from version 3 to version 8.

If all you want is a unique ID, you should call `uuid4()`.

Expand All @@ -13,7 +13,7 @@ If you're regularly generating more than thousand UUIDs per second, you might wa

## Minimal UUID v4 implementation

Credits go to [this answer][stackoverflow uuid4] on Stackoverflow for this minimal RFC 4122 compliant solution.
Credits go to [this answer][stackoverflow uuid4] on Stackoverflow for this minimal RFC 9562 compliant solution.
```php
<?php
function uuid4()
Expand Down Expand Up @@ -205,6 +205,5 @@ var_dump($uuid_version); // int(4)

14 bits dedicated to sub-second precision provide 100 nanosecond resolution. The `unix_ts_ms` and `subsec` fields guarantee the order of UUIDs generated within the same timestamp by monotonically incrementing the timer.

[RFC 4122]: http://tools.ietf.org/html/rfc4122
[draft]: https://github.com/ietf-wg-uuidrev/rfc4122bis
[RFC 9562]: https://datatracker.ietf.org/doc/rfc9562/
[stackoverflow uuid4]: https://stackoverflow.com/a/15875555
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oittaa/uuid",
"type": "library",
"description": "A small PHP class for generating RFC 4122 version 3, 4, and 5 universally unique identifiers (UUID). Additionally supports draft versions 6, 7, and 8.",
"description": "A small PHP class for generating RFC 9562 universally unique identifiers (UUID) from version 3 to version 8.",
"keywords": [
"uuid",
"identifier",
Expand Down
21 changes: 10 additions & 11 deletions src/UUID.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,61 @@
namespace UUID;

/**
* Represents a universally unique identifier (UUID), according to RFC 4122.
* Represents a universally unique identifier (UUID), according to RFC 9562.
*
* This class provides the static methods `uuid3()`, `uuid4()`, `uuid5()`,
* `uuid6()`, `uuid7()`, and `uuid8()` for generating version 3, 4, 5,
* 6 (draft), 7 (draft), and 8 (draft) UUIDs.
* 6, 7, and 8 UUIDs.
*
* If all you want is a unique ID, you should call `uuid4()`.
*
* @link http://tools.ietf.org/html/rfc4122
* @link https://github.com/ietf-wg-uuidrev/rfc4122bis
* @link https://datatracker.ietf.org/doc/rfc9562/
* @link http://en.wikipedia.org/wiki/Universally_unique_identifier
*/
class UUID
{
/**
* When this namespace is specified, the name string is a fully-qualified domain name.
* @var string
* @link http://tools.ietf.org/html/rfc4122#appendix-C
* @link https://www.rfc-editor.org/rfc/rfc9562.html#name-namespace-id-usage-and-allo
*/
public const NAMESPACE_DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
/**
* When this namespace is specified, the name string is a URL.
* @var string
* @link http://tools.ietf.org/html/rfc4122#appendix-C
* @link https://www.rfc-editor.org/rfc/rfc9562.html#name-namespace-id-usage-and-allo
*/
public const NAMESPACE_URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
/**
* When this namespace is specified, the name string is an ISO OID.
* @var string
* @link http://tools.ietf.org/html/rfc4122#appendix-C
* @link https://www.rfc-editor.org/rfc/rfc9562.html#name-namespace-id-usage-and-allo
*/
public const NAMESPACE_OID = '6ba7b812-9dad-11d1-80b4-00c04fd430c8';
/**
* When this namespace is specified, the name string is an X.500 DN in DER or a text output format.
* @var string
* @link http://tools.ietf.org/html/rfc4122#appendix-C
* @link https://www.rfc-editor.org/rfc/rfc9562.html#name-namespace-id-usage-and-allo
*/
public const NAMESPACE_X500 = '6ba7b814-9dad-11d1-80b4-00c04fd430c8';
/**
* The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.
* @var string
* @link http://tools.ietf.org/html/rfc4122#section-4.1.7
* @link https://www.rfc-editor.org/rfc/rfc9562.html#name-nil-uuid
*/
public const NIL = '00000000-0000-0000-0000-000000000000';
/**
* The Max UUID is special form of UUID that is specified to have all 128 bits set to one.
* @var string
* @link https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-00.html#name-max-uuid
* @link https://www.rfc-editor.org/rfc/rfc9562.html#name-max-uuid
*/
public const MAX = 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF';

/**
* 0x01b21dd213814000 is the number of 100-ns intervals between the
* UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
* @var int
* @link https://tools.ietf.org/html/rfc4122#section-4.1.4
* @link https://www.rfc-editor.org/rfc/rfc9562.html#name-test-vectors
*/
public const TIME_OFFSET_INT = 0x01b21dd213814000;

Expand Down

0 comments on commit a0efdb6

Please sign in to comment.