aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/uuid/src/Uuid.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ramsey/uuid/src/Uuid.php')
-rw-r--r--vendor/ramsey/uuid/src/Uuid.php99
1 files changed, 82 insertions, 17 deletions
diff --git a/vendor/ramsey/uuid/src/Uuid.php b/vendor/ramsey/uuid/src/Uuid.php
index 6656aba02..e0384a50c 100644
--- a/vendor/ramsey/uuid/src/Uuid.php
+++ b/vendor/ramsey/uuid/src/Uuid.php
@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Ramsey\Uuid;
+use BadMethodCallException;
use DateTimeInterface;
use Ramsey\Uuid\Codec\CodecInterface;
use Ramsey\Uuid\Converter\NumberConverterInterface;
@@ -88,7 +89,7 @@ class Uuid implements UuidInterface
* The max UUID is a special form of UUID that is specified to have all 128
* bits set to one
*
- * @link https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.4 Max UUID
+ * @link https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis-00#section-5.10 Max UUID
*/
public const MAX = 'ffffffff-ffff-ffff-ffff-ffffffffffff';
@@ -173,18 +174,23 @@ class Uuid implements UuidInterface
/**
* Version 6 (reordered time) UUID
*
- * @link https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.1 UUID Version 6
+ * @link https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis-00#section-5.6 UUID Version 6
*/
public const UUID_TYPE_REORDERED_TIME = 6;
/**
* Version 7 (Unix Epoch time) UUID
*
- * @link https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.2 UUID Version 7
+ * @link https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis-00#section-5.7 UUID Version 7
*/
public const UUID_TYPE_UNIX_TIME = 7;
/**
+ * @link https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis-00#section-5.8 UUID Version 8
+ */
+ public const UUID_TYPE_CUSTOM = 8;
+
+ /**
* DCE Security principal domain
*
* @link https://pubs.opengroup.org/onlinepubs/9696989899/chap11.htm#tagcjh_14_05_01_01 DCE 1.1, ยง11.5.1.1
@@ -287,7 +293,7 @@ class Uuid implements UuidInterface
*/
public function serialize(): string
{
- return $this->getFields()->getBytes();
+ return $this->codec->encode($this);
}
/**
@@ -440,20 +446,20 @@ class Uuid implements UuidInterface
*/
public static function fromBytes(string $bytes): UuidInterface
{
- if (! self::$factoryReplaced && strlen($bytes) === 16) {
+ if (!self::$factoryReplaced && strlen($bytes) === 16) {
$base16Uuid = bin2hex($bytes);
// Note: we are calling `fromString` internally because we don't know if the given `$bytes` is a valid UUID
return self::fromString(
substr($base16Uuid, 0, 8)
- . '-'
- . substr($base16Uuid, 8, 4)
- . '-'
- . substr($base16Uuid, 12, 4)
- . '-'
- . substr($base16Uuid, 16, 4)
- . '-'
- . substr($base16Uuid, 20, 12)
+ . '-'
+ . substr($base16Uuid, 8, 4)
+ . '-'
+ . substr($base16Uuid, 12, 4)
+ . '-'
+ . substr($base16Uuid, 16, 4)
+ . '-'
+ . substr($base16Uuid, 20, 12)
);
}
@@ -479,7 +485,7 @@ class Uuid implements UuidInterface
public static function fromString(string $uuid): UuidInterface
{
$uuid = strtolower($uuid);
- if (! self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
+ if (!self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
assert($uuid !== '');
return new LazyUuidFromString($uuid);
@@ -510,6 +516,33 @@ class Uuid implements UuidInterface
}
/**
+ * Creates a UUID from the Hexadecimal object
+ *
+ * @param Hexadecimal $hex Hexadecimal object representing a hexadecimal number
+ *
+ * @return UuidInterface A UuidInterface instance created from the Hexadecimal
+ * object representing a hexadecimal number
+ *
+ * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants,
+ * but under constant factory setups, this method operates in functionally pure manners
+ * @psalm-suppress MixedInferredReturnType,MixedReturnStatement
+ */
+ public static function fromHexadecimal(Hexadecimal $hex): UuidInterface
+ {
+ $factory = self::getFactory();
+
+ if (method_exists($factory, 'fromHexadecimal')) {
+ /**
+ * @phpstan-ignore-next-line
+ * @psalm-suppress UndefinedInterfaceMethod
+ */
+ return self::getFactory()->fromHexadecimal($hex);
+ }
+
+ throw new BadMethodCallException('The method fromHexadecimal() does not exist on the provided factory');
+ }
+
+ /**
* Creates a UUID from a 128-bit integer string
*
* @param string $integer String representation of 128-bit integer
@@ -522,6 +555,7 @@ class Uuid implements UuidInterface
*/
public static function fromInteger(string $integer): UuidInterface
{
+ /** @psalm-suppress ImpureMethodCall */
return self::getFactory()->fromInteger($integer);
}
@@ -535,10 +569,11 @@ class Uuid implements UuidInterface
* @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants,
* but under constant factory setups, this method operates in functionally pure manners
*
- * @psalm-assert-if-true non-empty-string $uuid
+ * @psalm-assert-if-true =non-empty-string $uuid
*/
public static function isValid(string $uuid): bool
{
+ /** @psalm-suppress ImpureMethodCall */
return self::getFactory()->getValidator()->validate($uuid);
}
@@ -549,7 +584,7 @@ class Uuid implements UuidInterface
* @param Hexadecimal|int|string|null $node A 48-bit number representing the
* hardware address; this number may be represented as an integer or a
* hexadecimal string
- * @param int $clockSeq A 14-bit number used to help avoid duplicates that
+ * @param int|null $clockSeq A 14-bit number used to help avoid duplicates that
* could arise when the clock is set backwards in time or if the node ID
* changes
*
@@ -653,7 +688,7 @@ class Uuid implements UuidInterface
*
* @param Hexadecimal|null $node A 48-bit number representing the hardware
* address
- * @param int $clockSeq A 14-bit number used to help avoid duplicates that
+ * @param int|null $clockSeq A 14-bit number used to help avoid duplicates that
* could arise when the clock is set backwards in time or if the node ID
* changes
*
@@ -690,4 +725,34 @@ class Uuid implements UuidInterface
'The provided factory does not support the uuid7() method',
);
}
+
+ /**
+ * Returns a version 8 (custom) UUID
+ *
+ * The bytes provided may contain any value according to your application's
+ * needs. Be aware, however, that other applications may not understand the
+ * semantics of the value.
+ *
+ * @param string $bytes A 16-byte octet string. This is an open blob
+ * of data that you may fill with 128 bits of information. Be aware,
+ * however, bits 48 through 51 will be replaced with the UUID version
+ * field, and bits 64 and 65 will be replaced with the UUID variant. You
+ * MUST NOT rely on these bits for your application needs.
+ *
+ * @return UuidInterface A UuidInterface instance that represents a
+ * version 8 UUID
+ */
+ public static function uuid8(string $bytes): UuidInterface
+ {
+ $factory = self::getFactory();
+
+ if (method_exists($factory, 'uuid8')) {
+ /** @var UuidInterface */
+ return $factory->uuid8($bytes);
+ }
+
+ throw new UnsupportedOperationException(
+ 'The provided factory does not support the uuid8() method',
+ );
+ }
}