aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/uuid/src/Rfc4122/Fields.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ramsey/uuid/src/Rfc4122/Fields.php')
-rw-r--r--vendor/ramsey/uuid/src/Rfc4122/Fields.php85
1 files changed, 42 insertions, 43 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;
}