aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/uuid/src/Rfc4122
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ramsey/uuid/src/Rfc4122')
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/Fields.php85
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php4
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/MaxTrait.php41
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/MaxUuid.php27
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php55
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php47
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php7
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/UuidV1.php40
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/UuidV2.php56
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/UuidV6.php29
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/UuidV7.php60
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/Validator.php5
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php24
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php27
14 files changed, 334 insertions, 173 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;
}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php b/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php
index a303525d6..2241cf574 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php
@@ -103,11 +103,13 @@ interface FieldsInterface extends BaseFieldsInterface
* The version number describes how the UUID was generated and has the
* following meaning:
*
- * 1. Time-based UUID
+ * 1. Gregorian time UUID
* 2. DCE security UUID
* 3. Name-based UUID hashed with MD5
* 4. Randomly generated UUID
* 5. Name-based UUID hashed with SHA-1
+ * 6. Reordered time UUID
+ * 7. Unix Epoch time UUID
*
* This returns `null` if the UUID is not an RFC 4122 variant, since version
* is only meaningful for this variant.
diff --git a/vendor/ramsey/uuid/src/Rfc4122/MaxTrait.php b/vendor/ramsey/uuid/src/Rfc4122/MaxTrait.php
new file mode 100644
index 000000000..2ec304723
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Rfc4122/MaxTrait.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * This file is part of the ramsey/uuid library
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
+ * @license http://opensource.org/licenses/MIT MIT
+ */
+
+declare(strict_types=1);
+
+namespace Ramsey\Uuid\Rfc4122;
+
+/**
+ * Provides common functionality for max UUIDs
+ *
+ * The max UUID is special form of UUID that is specified to have all 128 bits
+ * set to one. It is the inverse of the nil UUID.
+ *
+ * @link https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.4 Max UUID
+ *
+ * @psalm-immutable
+ */
+trait MaxTrait
+{
+ /**
+ * Returns the bytes that comprise the fields
+ */
+ abstract public function getBytes(): string;
+
+ /**
+ * Returns true if the byte string represents a max UUID
+ */
+ public function isMax(): bool
+ {
+ return $this->getBytes() === "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
+ }
+}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/MaxUuid.php b/vendor/ramsey/uuid/src/Rfc4122/MaxUuid.php
new file mode 100644
index 000000000..e5ffa72c6
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Rfc4122/MaxUuid.php
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * This file is part of the ramsey/uuid library
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
+ * @license http://opensource.org/licenses/MIT MIT
+ */
+
+declare(strict_types=1);
+
+namespace Ramsey\Uuid\Rfc4122;
+
+use Ramsey\Uuid\Uuid;
+
+/**
+ * The max UUID is special form of UUID that is specified to have all 128 bits
+ * set to one
+ *
+ * @psalm-immutable
+ */
+final class MaxUuid extends Uuid implements UuidInterface
+{
+}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php b/vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php
new file mode 100644
index 000000000..5d939fac6
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * This file is part of the ramsey/uuid library
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
+ * @license http://opensource.org/licenses/MIT MIT
+ */
+
+declare(strict_types=1);
+
+namespace Ramsey\Uuid\Rfc4122;
+
+use DateTimeImmutable;
+use DateTimeInterface;
+use Ramsey\Uuid\Exception\DateTimeException;
+use Throwable;
+
+use function str_pad;
+
+use const STR_PAD_LEFT;
+
+/**
+ * Provides common functionality for getting the time from a time-based UUID
+ *
+ * @psalm-immutable
+ */
+trait TimeTrait
+{
+ /**
+ * Returns a DateTimeInterface object representing the timestamp associated
+ * with the UUID
+ *
+ * @return DateTimeImmutable A PHP DateTimeImmutable instance representing
+ * the timestamp of a time-based UUID
+ */
+ public function getDateTime(): DateTimeInterface
+ {
+ $time = $this->timeConverter->convertTime($this->fields->getTimestamp());
+
+ try {
+ return new DateTimeImmutable(
+ '@'
+ . $time->getSeconds()->toString()
+ . '.'
+ . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT)
+ );
+ } catch (Throwable $e) {
+ throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);
+ }
+ }
+}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php b/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php
index 736931af2..859649fd9 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php
@@ -17,11 +17,13 @@ namespace Ramsey\Uuid\Rfc4122;
use Ramsey\Uuid\Builder\UuidBuilderInterface;
use Ramsey\Uuid\Codec\CodecInterface;
use Ramsey\Uuid\Converter\NumberConverterInterface;
+use Ramsey\Uuid\Converter\Time\UnixTimeConverter;
use Ramsey\Uuid\Converter\TimeConverterInterface;
use Ramsey\Uuid\Exception\UnableToBuildUuidException;
use Ramsey\Uuid\Exception\UnsupportedOperationException;
-use Ramsey\Uuid\Nonstandard\UuidV6;
+use Ramsey\Uuid\Math\BrickMathCalculator;
use Ramsey\Uuid\Rfc4122\UuidInterface as Rfc4122UuidInterface;
+use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Throwable;
@@ -32,15 +34,7 @@ use Throwable;
*/
class UuidBuilder implements UuidBuilderInterface
{
- /**
- * @var NumberConverterInterface
- */
- private $numberConverter;
-
- /**
- * @var TimeConverterInterface
- */
- private $timeConverter;
+ private TimeConverterInterface $unixTimeConverter;
/**
* Constructs the DefaultUuidBuilder
@@ -48,14 +42,18 @@ class UuidBuilder implements UuidBuilderInterface
* @param NumberConverterInterface $numberConverter The number converter to
* use when constructing the Uuid
* @param TimeConverterInterface $timeConverter The time converter to use
- * for converting timestamps extracted from a UUID to Unix timestamps
+ * for converting Gregorian time extracted from version 1, 2, and 6
+ * UUIDs to Unix timestamps
+ * @param TimeConverterInterface|null $unixTimeConverter The time converter
+ * to use for converter Unix Epoch time extracted from version 7 UUIDs
+ * to Unix timestamps
*/
public function __construct(
- NumberConverterInterface $numberConverter,
- TimeConverterInterface $timeConverter
+ private NumberConverterInterface $numberConverter,
+ private TimeConverterInterface $timeConverter,
+ ?TimeConverterInterface $unixTimeConverter = null
) {
- $this->numberConverter = $numberConverter;
- $this->timeConverter = $timeConverter;
+ $this->unixTimeConverter = $unixTimeConverter ?? new UnixTimeConverter(new BrickMathCalculator());
}
/**
@@ -71,25 +69,32 @@ class UuidBuilder implements UuidBuilderInterface
public function build(CodecInterface $codec, string $bytes): UuidInterface
{
try {
+ /** @var Fields $fields */
$fields = $this->buildFields($bytes);
if ($fields->isNil()) {
return new NilUuid($fields, $this->numberConverter, $codec, $this->timeConverter);
}
+ if ($fields->isMax()) {
+ return new MaxUuid($fields, $this->numberConverter, $codec, $this->timeConverter);
+ }
+
switch ($fields->getVersion()) {
- case 1:
+ case Uuid::UUID_TYPE_TIME:
return new UuidV1($fields, $this->numberConverter, $codec, $this->timeConverter);
- case 2:
+ case Uuid::UUID_TYPE_DCE_SECURITY:
return new UuidV2($fields, $this->numberConverter, $codec, $this->timeConverter);
- case 3:
+ case Uuid::UUID_TYPE_HASH_MD5:
return new UuidV3($fields, $this->numberConverter, $codec, $this->timeConverter);
- case 4:
+ case Uuid::UUID_TYPE_RANDOM:
return new UuidV4($fields, $this->numberConverter, $codec, $this->timeConverter);
- case 5:
+ case Uuid::UUID_TYPE_HASH_SHA1:
return new UuidV5($fields, $this->numberConverter, $codec, $this->timeConverter);
- case 6:
+ case Uuid::UUID_TYPE_REORDERED_TIME:
return new UuidV6($fields, $this->numberConverter, $codec, $this->timeConverter);
+ case Uuid::UUID_TYPE_UNIX_TIME:
+ return new UuidV7($fields, $this->numberConverter, $codec, $this->unixTimeConverter);
}
throw new UnsupportedOperationException(
diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php b/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php
index 3e4d9faee..e80f33bef 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php
@@ -26,11 +26,4 @@ use Ramsey\Uuid\UuidInterface as BaseUuidInterface;
*/
interface UuidInterface extends BaseUuidInterface
{
- /**
- * Returns the string standard representation of the UUID as a URN
- *
- * @link http://en.wikipedia.org/wiki/Uniform_Resource_Name Uniform Resource Name
- * @link https://tools.ietf.org/html/rfc4122#section-3 RFC 4122, § 3: Namespace Registration Template
- */
- public function getUrn(): string;
}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php
index 764e42f84..515c038d9 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php
@@ -14,31 +14,25 @@ declare(strict_types=1);
namespace Ramsey\Uuid\Rfc4122;
-use DateTimeImmutable;
-use DateTimeInterface;
use Ramsey\Uuid\Codec\CodecInterface;
use Ramsey\Uuid\Converter\NumberConverterInterface;
use Ramsey\Uuid\Converter\TimeConverterInterface;
-use Ramsey\Uuid\Exception\DateTimeException;
use Ramsey\Uuid\Exception\InvalidArgumentException;
use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
use Ramsey\Uuid\Uuid;
-use Throwable;
-
-use function str_pad;
-
-use const STR_PAD_LEFT;
/**
- * Time-based, or version 1, UUIDs include timestamp, clock sequence, and node
+ * Gregorian time, or version 1, UUIDs include timestamp, clock sequence, and node
* values that are combined into a 128-bit unsigned integer
*
* @psalm-immutable
*/
final class UuidV1 extends Uuid implements UuidInterface
{
+ use TimeTrait;
+
/**
- * Creates a version 1 (time-based) UUID
+ * Creates a version 1 (Gregorian time) UUID
*
* @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID
* @param NumberConverterInterface $numberConverter The number converter to use
@@ -63,30 +57,4 @@ final class UuidV1 extends Uuid implements UuidInterface
parent::__construct($fields, $numberConverter, $codec, $timeConverter);
}
-
- /**
- * Returns a DateTimeInterface object representing the timestamp associated
- * with the UUID
- *
- * The timestamp value is only meaningful in a time-based UUID, which
- * has version type 1.
- *
- * @return DateTimeImmutable A PHP DateTimeImmutable instance representing
- * the timestamp of a version 1 UUID
- */
- public function getDateTime(): DateTimeInterface
- {
- $time = $this->timeConverter->convertTime($this->fields->getTimestamp());
-
- try {
- return new DateTimeImmutable(
- '@'
- . $time->getSeconds()->toString()
- . '.'
- . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT)
- );
- } catch (Throwable $e) {
- throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);
- }
- }
}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php
index 74906f050..c8ccbe422 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php
@@ -14,28 +14,33 @@ declare(strict_types=1);
namespace Ramsey\Uuid\Rfc4122;
-use DateTimeImmutable;
-use DateTimeInterface;
use Ramsey\Uuid\Codec\CodecInterface;
use Ramsey\Uuid\Converter\NumberConverterInterface;
use Ramsey\Uuid\Converter\TimeConverterInterface;
-use Ramsey\Uuid\Exception\DateTimeException;
use Ramsey\Uuid\Exception\InvalidArgumentException;
use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
use Ramsey\Uuid\Type\Integer as IntegerObject;
use Ramsey\Uuid\Uuid;
-use Throwable;
use function hexdec;
-use function str_pad;
-
-use const STR_PAD_LEFT;
/**
* DCE Security version, or version 2, UUIDs include local domain identifier,
* local ID for the specified domain, and node values that are combined into a
* 128-bit unsigned integer
*
+ * It is important to note that a version 2 UUID suffers from some loss of
+ * fidelity of the timestamp, due to replacing the time_low field with the
+ * local identifier. When constructing the timestamp value for date
+ * purposes, we replace the local identifier bits with zeros. As a result,
+ * the timestamp can be off by a range of 0 to 429.4967295 seconds (or 7
+ * minutes, 9 seconds, and 496730 microseconds).
+ *
+ * Astute observers might note this value directly corresponds to 2^32 - 1,
+ * or 0xffffffff. The local identifier is 32-bits, and we have set each of
+ * these bits to 0, so the maximum range of timestamp drift is 0x00000000
+ * to 0xffffffff (counted in 100-nanosecond intervals).
+ *
* @link https://publications.opengroup.org/c311 DCE 1.1: Authentication and Security Services
* @link https://publications.opengroup.org/c706 DCE 1.1: Remote Procedure Call
* @link https://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01 DCE 1.1: Auth & Sec, §5.2.1.1
@@ -47,6 +52,8 @@ use const STR_PAD_LEFT;
*/
final class UuidV2 extends Uuid implements UuidInterface
{
+ use TimeTrait;
+
/**
* Creates a version 2 (DCE Security) UUID
*
@@ -75,41 +82,6 @@ final class UuidV2 extends Uuid implements UuidInterface
}
/**
- * Returns a DateTimeInterface object representing the timestamp associated
- * with the UUID
- *
- * It is important to note that a version 2 UUID suffers from some loss of
- * fidelity of the timestamp, due to replacing the time_low field with the
- * local identifier. When constructing the timestamp value for date
- * purposes, we replace the local identifier bits with zeros. As a result,
- * the timestamp can be off by a range of 0 to 429.4967295 seconds (or 7
- * minutes, 9 seconds, and 496730 microseconds).
- *
- * Astute observers might note this value directly corresponds to 2^32 - 1,
- * or 0xffffffff. The local identifier is 32-bits, and we have set each of
- * these bits to 0, so the maximum range of timestamp drift is 0x00000000
- * to 0xffffffff (counted in 100-nanosecond intervals).
- *
- * @return DateTimeImmutable A PHP DateTimeImmutable instance representing
- * the timestamp of a version 2 UUID
- */
- public function getDateTime(): DateTimeInterface
- {
- $time = $this->timeConverter->convertTime($this->fields->getTimestamp());
-
- try {
- return new DateTimeImmutable(
- '@'
- . $time->getSeconds()->toString()
- . '.'
- . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT)
- );
- } catch (Throwable $e) {
- throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);
- }
- }
-
- /**
* Returns the local domain used to create this version 2 UUID
*/
public function getLocalDomain(): int
diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV6.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV6.php
new file mode 100644
index 000000000..9b2ddee00
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV6.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * This file is part of the ramsey/uuid library
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
+ * @license http://opensource.org/licenses/MIT MIT
+ */
+
+declare(strict_types=1);
+
+namespace Ramsey\Uuid\Rfc4122;
+
+use Ramsey\Uuid\Nonstandard\UuidV6 as NonstandardUuidV6;
+
+/**
+ * Reordered time, or version 6, UUIDs include timestamp, clock sequence, and
+ * node values that are combined into a 128-bit unsigned integer
+ *
+ * @link https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.1 UUID Version 6
+ *
+ * @psalm-immutable
+ */
+final class UuidV6 extends NonstandardUuidV6 implements UuidInterface
+{
+}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV7.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV7.php
new file mode 100644
index 000000000..90c2471ac
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV7.php
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * This file is part of the ramsey/uuid library
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
+ * @license http://opensource.org/licenses/MIT MIT
+ */
+
+declare(strict_types=1);
+
+namespace Ramsey\Uuid\Rfc4122;
+
+use Ramsey\Uuid\Codec\CodecInterface;
+use Ramsey\Uuid\Converter\NumberConverterInterface;
+use Ramsey\Uuid\Converter\TimeConverterInterface;
+use Ramsey\Uuid\Exception\InvalidArgumentException;
+use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
+use Ramsey\Uuid\Uuid;
+
+/**
+ * Gregorian time, or version 1, UUIDs include timestamp, clock sequence, and node
+ * values that are combined into a 128-bit unsigned integer
+ *
+ * @psalm-immutable
+ */
+final class UuidV7 extends Uuid implements UuidInterface
+{
+ use TimeTrait;
+
+ /**
+ * Creates a version 7 (Unix Epoch time) UUID
+ *
+ * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID
+ * @param NumberConverterInterface $numberConverter The number converter to use
+ * for converting hex values to/from integers
+ * @param CodecInterface $codec The codec to use when encoding or decoding
+ * UUID strings
+ * @param TimeConverterInterface $timeConverter The time converter to use
+ * for converting timestamps extracted from a UUID to unix timestamps
+ */
+ public function __construct(
+ Rfc4122FieldsInterface $fields,
+ NumberConverterInterface $numberConverter,
+ CodecInterface $codec,
+ TimeConverterInterface $timeConverter
+ ) {
+ if ($fields->getVersion() !== Uuid::UUID_TYPE_UNIX_TIME) {
+ throw new InvalidArgumentException(
+ 'Fields used to create a UuidV7 must represent a '
+ . 'version 7 (Unix Epoch time) UUID'
+ );
+ }
+
+ parent::__construct($fields, $numberConverter, $codec, $timeConverter);
+ }
+}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/Validator.php b/vendor/ramsey/uuid/src/Rfc4122/Validator.php
index ed43c982f..6b1f0de06 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/Validator.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/Validator.php
@@ -28,7 +28,7 @@ use function str_replace;
final class Validator implements ValidatorInterface
{
private const VALID_PATTERN = '\A[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-'
- . '[1-5]{1}[0-9A-Fa-f]{3}-[ABab89]{1}[0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}\z';
+ . '[1-7][0-9A-Fa-f]{3}-[ABab89][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}\z';
/**
* @psalm-return non-empty-string
@@ -43,7 +43,8 @@ final class Validator implements ValidatorInterface
public function validate(string $uuid): bool
{
$uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid);
+ $uuid = strtolower($uuid);
- return $uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid);
+ return $uuid === Uuid::NIL || $uuid === Uuid::MAX || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid);
}
}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php b/vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php
index 4c981658f..1041de51e 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php
@@ -19,8 +19,8 @@ use Ramsey\Uuid\Uuid;
use function decbin;
use function str_pad;
+use function str_starts_with;
use function strlen;
-use function strpos;
use function substr;
use function unpack;
@@ -58,7 +58,13 @@ trait VariantTrait
throw new InvalidBytesException('Invalid number of bytes');
}
- /** @var array $parts */
+ if ($this->isMax() || $this->isNil()) {
+ // RFC 4122 defines these special types of UUID, so we will consider
+ // them as belonging to the RFC 4122 variant.
+ return Uuid::RFC_4122;
+ }
+
+ /** @var int[] $parts */
$parts = unpack('n*', $this->getBytes());
// $parts[5] is a 16-bit, unsigned integer containing the variant bits
@@ -67,7 +73,7 @@ trait VariantTrait
// three characters (three most-significant bits) to determine the
// variant.
$binary = str_pad(
- decbin((int) $parts[5]),
+ decbin($parts[5]),
16,
'0',
STR_PAD_LEFT
@@ -76,15 +82,13 @@ trait VariantTrait
$msb = substr($binary, 0, 3);
if ($msb === '111') {
- $variant = Uuid::RESERVED_FUTURE;
+ return Uuid::RESERVED_FUTURE;
} elseif ($msb === '110') {
- $variant = Uuid::RESERVED_MICROSOFT;
- } elseif (strpos($msb, '10') === 0) {
- $variant = Uuid::RFC_4122;
- } else {
- $variant = Uuid::RESERVED_NCS;
+ return Uuid::RESERVED_MICROSOFT;
+ } elseif (str_starts_with($msb, '10')) {
+ return Uuid::RFC_4122;
}
- return $variant;
+ return Uuid::RESERVED_NCS;
}
}
diff --git a/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php b/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php
index cee55fbef..316f780c4 100644
--- a/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php
+++ b/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php
@@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Ramsey\Uuid\Rfc4122;
+use Ramsey\Uuid\Uuid;
+
/**
* Provides common functionality for handling the version, as defined by RFC 4122
*
@@ -27,6 +29,11 @@ trait VersionTrait
abstract public function getVersion(): ?int;
/**
+ * Returns true if these fields represent a max UUID
+ */
+ abstract public function isMax(): bool;
+
+ /**
* Returns true if these fields represent a nil UUID
*/
abstract public function isNil(): bool;
@@ -38,20 +45,16 @@ trait VersionTrait
*/
private function isCorrectVersion(): bool
{
- if ($this->isNil()) {
+ if ($this->isNil() || $this->isMax()) {
return true;
}
- switch ($this->getVersion()) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- return true;
- }
-
- return false;
+ return match ($this->getVersion()) {
+ Uuid::UUID_TYPE_TIME, Uuid::UUID_TYPE_DCE_SECURITY,
+ Uuid::UUID_TYPE_HASH_MD5, Uuid::UUID_TYPE_RANDOM,
+ Uuid::UUID_TYPE_HASH_SHA1, Uuid::UUID_TYPE_REORDERED_TIME,
+ Uuid::UUID_TYPE_UNIX_TIME => true,
+ default => false,
+ };
}
}