diff options
Diffstat (limited to 'vendor/ramsey/uuid/src/Rfc4122')
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/Fields.php | 85 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php | 4 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/MaxTrait.php | 41 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/MaxUuid.php | 27 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php | 55 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php | 47 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php | 7 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/UuidV1.php | 40 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/UuidV2.php | 56 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/UuidV6.php | 29 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/UuidV7.php | 60 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/Validator.php | 5 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php | 24 | ||||
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php | 27 |
14 files changed, 173 insertions, 334 deletions
diff --git a/vendor/ramsey/uuid/src/Rfc4122/Fields.php b/vendor/ramsey/uuid/src/Rfc4122/Fields.php index 9acf810c2..2ccc20bb6 100644 --- a/vendor/ramsey/uuid/src/Rfc4122/Fields.php +++ b/vendor/ramsey/uuid/src/Rfc4122/Fields.php @@ -40,28 +40,34 @@ 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(private string $bytes) + public function __construct(string $bytes) { - if (strlen($this->bytes) !== 16) { + if (strlen($bytes) !== 16) { throw new InvalidArgumentException( 'The byte string must be 16 bytes long; ' - . 'received ' . strlen($this->bytes) . ' bytes' + . 'received ' . strlen($bytes) . ' bytes' ); } + $this->bytes = $bytes; + if (!$this->isCorrectVariant()) { throw new InvalidArgumentException( 'The byte string received does not conform to the RFC 4122 variant' @@ -82,13 +88,7 @@ final class Fields implements FieldsInterface public function getClockSeq(): Hexadecimal { - if ($this->isMax()) { - $clockSeq = 0xffff; - } elseif ($this->isNil()) { - $clockSeq = 0x0000; - } else { - $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff; - } + $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff; return new Hexadecimal(str_pad(dechex($clockSeq), 4, '0', STR_PAD_LEFT)); } @@ -140,53 +140,52 @@ final class Fields implements FieldsInterface */ public function getTimestamp(): Hexadecimal { - $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() - ), - }; + 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() + ); + } return new Hexadecimal($timestamp); } public function getVersion(): ?int { - if ($this->isNil() || $this->isMax()) { + if ($this->isNil()) { return null; } - /** @var int[] $parts */ + /** @var array $parts */ $parts = unpack('n*', $this->bytes); - return $parts[4] >> 12; + return (int) $parts[4] >> 12; } private function isCorrectVariant(): bool { - if ($this->isNil() || $this->isMax()) { + if ($this->isNil()) { return true; } diff --git a/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php b/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php index 2241cf574..a303525d6 100644 --- a/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php +++ b/vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php @@ -103,13 +103,11 @@ interface FieldsInterface extends BaseFieldsInterface * The version number describes how the UUID was generated and has the * following meaning: * - * 1. Gregorian time UUID + * 1. Time-based 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 deleted file mode 100644 index 2ec304723..000000000 --- a/vendor/ramsey/uuid/src/Rfc4122/MaxTrait.php +++ /dev/null @@ -1,41 +0,0 @@ -<?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 deleted file mode 100644 index e5ffa72c6..000000000 --- a/vendor/ramsey/uuid/src/Rfc4122/MaxUuid.php +++ /dev/null @@ -1,27 +0,0 @@ -<?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 deleted file mode 100644 index 5d939fac6..000000000 --- a/vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php +++ /dev/null @@ -1,55 +0,0 @@ -<?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 859649fd9..736931af2 100644 --- a/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php @@ -17,13 +17,11 @@ 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\Math\BrickMathCalculator; +use Ramsey\Uuid\Nonstandard\UuidV6; use Ramsey\Uuid\Rfc4122\UuidInterface as Rfc4122UuidInterface; -use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; use Throwable; @@ -34,7 +32,15 @@ use Throwable; */ class UuidBuilder implements UuidBuilderInterface { - private TimeConverterInterface $unixTimeConverter; + /** + * @var NumberConverterInterface + */ + private $numberConverter; + + /** + * @var TimeConverterInterface + */ + private $timeConverter; /** * Constructs the DefaultUuidBuilder @@ -42,18 +48,14 @@ 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 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 + * for converting timestamps extracted from a UUID to Unix timestamps */ public function __construct( - private NumberConverterInterface $numberConverter, - private TimeConverterInterface $timeConverter, - ?TimeConverterInterface $unixTimeConverter = null + NumberConverterInterface $numberConverter, + TimeConverterInterface $timeConverter ) { - $this->unixTimeConverter = $unixTimeConverter ?? new UnixTimeConverter(new BrickMathCalculator()); + $this->numberConverter = $numberConverter; + $this->timeConverter = $timeConverter; } /** @@ -69,32 +71,25 @@ 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 Uuid::UUID_TYPE_TIME: + case 1: return new UuidV1($fields, $this->numberConverter, $codec, $this->timeConverter); - case Uuid::UUID_TYPE_DCE_SECURITY: + case 2: return new UuidV2($fields, $this->numberConverter, $codec, $this->timeConverter); - case Uuid::UUID_TYPE_HASH_MD5: + case 3: return new UuidV3($fields, $this->numberConverter, $codec, $this->timeConverter); - case Uuid::UUID_TYPE_RANDOM: + case 4: return new UuidV4($fields, $this->numberConverter, $codec, $this->timeConverter); - case Uuid::UUID_TYPE_HASH_SHA1: + case 5: return new UuidV5($fields, $this->numberConverter, $codec, $this->timeConverter); - case Uuid::UUID_TYPE_REORDERED_TIME: + case 6: 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 e80f33bef..3e4d9faee 100644 --- a/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php @@ -26,4 +26,11 @@ 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 515c038d9..764e42f84 100644 --- a/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV1.php @@ -14,25 +14,31 @@ 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; /** - * Gregorian time, or version 1, UUIDs include timestamp, clock sequence, and node + * Time-based, 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 (Gregorian time) UUID + * Creates a version 1 (time-based) UUID * * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID * @param NumberConverterInterface $numberConverter The number converter to use @@ -57,4 +63,30 @@ 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 c8ccbe422..74906f050 100644 --- a/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php @@ -14,33 +14,28 @@ 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 @@ -52,8 +47,6 @@ use function hexdec; */ final class UuidV2 extends Uuid implements UuidInterface { - use TimeTrait; - /** * Creates a version 2 (DCE Security) UUID * @@ -82,6 +75,41 @@ 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 deleted file mode 100644 index 9b2ddee00..000000000 --- a/vendor/ramsey/uuid/src/Rfc4122/UuidV6.php +++ /dev/null @@ -1,29 +0,0 @@ -<?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 deleted file mode 100644 index 90c2471ac..000000000 --- a/vendor/ramsey/uuid/src/Rfc4122/UuidV7.php +++ /dev/null @@ -1,60 +0,0 @@ -<?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 6b1f0de06..ed43c982f 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-7][0-9A-Fa-f]{3}-[ABab89][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}\z'; + . '[1-5]{1}[0-9A-Fa-f]{3}-[ABab89]{1}[0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}\z'; /** * @psalm-return non-empty-string @@ -43,8 +43,7 @@ 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 || $uuid === Uuid::MAX || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid); + return $uuid === Uuid::NIL || 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 1041de51e..4c981658f 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,13 +58,7 @@ trait VariantTrait throw new InvalidBytesException('Invalid number of bytes'); } - 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 */ + /** @var array $parts */ $parts = unpack('n*', $this->getBytes()); // $parts[5] is a 16-bit, unsigned integer containing the variant bits @@ -73,7 +67,7 @@ trait VariantTrait // three characters (three most-significant bits) to determine the // variant. $binary = str_pad( - decbin($parts[5]), + decbin((int) $parts[5]), 16, '0', STR_PAD_LEFT @@ -82,13 +76,15 @@ trait VariantTrait $msb = substr($binary, 0, 3); if ($msb === '111') { - return Uuid::RESERVED_FUTURE; + $variant = Uuid::RESERVED_FUTURE; } elseif ($msb === '110') { - return Uuid::RESERVED_MICROSOFT; - } elseif (str_starts_with($msb, '10')) { - return Uuid::RFC_4122; + $variant = Uuid::RESERVED_MICROSOFT; + } elseif (strpos($msb, '10') === 0) { + $variant = Uuid::RFC_4122; + } else { + $variant = Uuid::RESERVED_NCS; } - return Uuid::RESERVED_NCS; + return $variant; } } diff --git a/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php b/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php index 316f780c4..cee55fbef 100644 --- a/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php +++ b/vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php @@ -14,8 +14,6 @@ declare(strict_types=1); namespace Ramsey\Uuid\Rfc4122; -use Ramsey\Uuid\Uuid; - /** * Provides common functionality for handling the version, as defined by RFC 4122 * @@ -29,11 +27,6 @@ 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; @@ -45,16 +38,20 @@ trait VersionTrait */ private function isCorrectVersion(): bool { - if ($this->isNil() || $this->isMax()) { + if ($this->isNil()) { return true; } - 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, - }; + switch ($this->getVersion()) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + return true; + } + + return false; } } |