aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/uuid/src/Rfc4122/Fields.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2022-10-12 08:45:01 +0000
committerMario <mario@mariovavti.com>2022-10-12 08:45:01 +0000
commit8bf5c18425cf15327fa11494e6e0d3749f36c6f8 (patch)
treefc358336312cd23030321a43f276db19cea17621 /vendor/ramsey/uuid/src/Rfc4122/Fields.php
parentc36bb17475b3dd5925cefc32752f1fb8a63df154 (diff)
downloadvolse-hubzilla-8bf5c18425cf15327fa11494e6e0d3749f36c6f8.tar.gz
volse-hubzilla-8bf5c18425cf15327fa11494e6e0d3749f36c6f8.tar.bz2
volse-hubzilla-8bf5c18425cf15327fa11494e6e0d3749f36c6f8.zip
composer update ramsey/uuid
Diffstat (limited to 'vendor/ramsey/uuid/src/Rfc4122/Fields.php')
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/Fields.php85
1 files changed, 43 insertions, 42 deletions
diff --git a/vendor/ramsey/uuid/src/Rfc4122/Fields.php b/vendor/ramsey/uuid/src/Rfc4122/Fields.php
index 2ccc20bb6..9acf810c2 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/Fields.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/Fields.php
@@ -40,34 +40,28 @@ use const STR_PAD_LEFT;
*/
final class Fields implements FieldsInterface
{
+ use MaxTrait;
use NilTrait;
use SerializableFieldsTrait;
use VariantTrait;
use VersionTrait;
/**
- * @var string
- */
- private $bytes;
-
- /**
* @param string $bytes A 16-byte binary string representation of a UUID
*
* @throws InvalidArgumentException if the byte string is not exactly 16 bytes
* @throws InvalidArgumentException if the byte string does not represent an RFC 4122 UUID
* @throws InvalidArgumentException if the byte string does not contain a valid version
*/
- public function __construct(string $bytes)
+ public function __construct(private string $bytes)
{
- if (strlen($bytes) !== 16) {
+ if (strlen($this->bytes) !== 16) {
throw new InvalidArgumentException(
'The byte string must be 16 bytes long; '
- . 'received ' . strlen($bytes) . ' bytes'
+ . 'received ' . strlen($this->bytes) . ' bytes'
);
}
- $this->bytes = $bytes;
-
if (!$this->isCorrectVariant()) {
throw new InvalidArgumentException(
'The byte string received does not conform to the RFC 4122 variant'
@@ -88,7 +82,13 @@ final class Fields implements FieldsInterface
public function getClockSeq(): Hexadecimal
{
- $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff;
+ if ($this->isMax()) {
+ $clockSeq = 0xffff;
+ } elseif ($this->isNil()) {
+ $clockSeq = 0x0000;
+ } else {
+ $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff;
+ }
return new Hexadecimal(str_pad(dechex($clockSeq), 4, '0', STR_PAD_LEFT));
}
@@ -140,52 +140,53 @@ final class Fields implements FieldsInterface
*/
public function getTimestamp(): Hexadecimal
{
- switch ($this->getVersion()) {
- case Uuid::UUID_TYPE_DCE_SECURITY:
- $timestamp = sprintf(
- '%03x%04s%08s',
- hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff,
- $this->getTimeMid()->toString(),
- ''
- );
-
- break;
- case Uuid::UUID_TYPE_PEABODY:
- $timestamp = sprintf(
- '%08s%04s%03x',
- $this->getTimeLow()->toString(),
- $this->getTimeMid()->toString(),
- hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff
- );
-
- break;
- default:
- $timestamp = sprintf(
- '%03x%04s%08s',
- hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff,
- $this->getTimeMid()->toString(),
- $this->getTimeLow()->toString()
- );
- }
+ $timestamp = match ($this->getVersion()) {
+ Uuid::UUID_TYPE_DCE_SECURITY => sprintf(
+ '%03x%04s%08s',
+ hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff,
+ $this->getTimeMid()->toString(),
+ ''
+ ),
+ Uuid::UUID_TYPE_REORDERED_TIME => sprintf(
+ '%08s%04s%03x',
+ $this->getTimeLow()->toString(),
+ $this->getTimeMid()->toString(),
+ hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff
+ ),
+ // The Unix timestamp in version 7 UUIDs is a 48-bit number,
+ // but for consistency, we will return a 60-bit number, padded
+ // to the left with zeros.
+ Uuid::UUID_TYPE_UNIX_TIME => sprintf(
+ '%011s%04s',
+ $this->getTimeLow()->toString(),
+ $this->getTimeMid()->toString(),
+ ),
+ default => sprintf(
+ '%03x%04s%08s',
+ hexdec($this->getTimeHiAndVersion()->toString()) & 0x0fff,
+ $this->getTimeMid()->toString(),
+ $this->getTimeLow()->toString()
+ ),
+ };
return new Hexadecimal($timestamp);
}
public function getVersion(): ?int
{
- if ($this->isNil()) {
+ if ($this->isNil() || $this->isMax()) {
return null;
}
- /** @var array $parts */
+ /** @var int[] $parts */
$parts = unpack('n*', $this->bytes);
- return (int) $parts[4] >> 12;
+ return $parts[4] >> 12;
}
private function isCorrectVariant(): bool
{
- if ($this->isNil()) {
+ if ($this->isNil() || $this->isMax()) {
return true;
}