mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-15 16:07:55 +03:00
Support version 6 UUIDs
See the following: * https://github.com/uuid6/uuid6-ietf-draft * http://gh.peabody.io/uuidv6/
This commit is contained in:
@@ -351,6 +351,27 @@ class UuidFactory implements UuidFactoryInterface
|
||||
return $this->uuidFromNsAndName($ns, $name, 5, 'sha1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function uuid6($node = null, ?int $clockSeq = null): UuidInterface
|
||||
{
|
||||
$bytes = $this->timeGenerator->generate($node, $clockSeq);
|
||||
|
||||
// Rearrange the bytes, according to the UUID version 6 specification.
|
||||
$v6 = $bytes[6] . $bytes[7] . $bytes[4] . $bytes[5]
|
||||
. $bytes[0] . $bytes[1] . $bytes[2] . $bytes[3];
|
||||
$v6 = bin2hex($v6);
|
||||
|
||||
// Drop the first four bits, while adding an empty four bits for the
|
||||
// version field. This allows us to reconstruct the correct time from
|
||||
// the bytes of this UUID.
|
||||
$v6Bytes = hex2bin(substr($v6, 1, 12) . '0' . substr($v6, -3));
|
||||
$v6Bytes .= substr($bytes, 8);
|
||||
|
||||
return $this->uuidFromBytesAndVersion($v6Bytes, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Uuid created from the provided byte string
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user