refactor: susun semula struktur folder — Laravel source ke src/
This commit is contained in:
190
vendor/ramsey/uuid/src/Rfc4122/Fields.php
vendored
Normal file
190
vendor/ramsey/uuid/src/Rfc4122/Fields.php
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
<?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\Exception\InvalidArgumentException;
|
||||
use Ramsey\Uuid\Fields\SerializableFieldsTrait;
|
||||
use Ramsey\Uuid\Type\Hexadecimal;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use function bin2hex;
|
||||
use function dechex;
|
||||
use function hexdec;
|
||||
use function sprintf;
|
||||
use function str_pad;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use function unpack;
|
||||
|
||||
use const STR_PAD_LEFT;
|
||||
|
||||
/**
|
||||
* RFC 9562 (formerly RFC 4122) variant UUIDs consist of a set of named fields
|
||||
*
|
||||
* Internally, this class represents the fields together as a 16-byte binary string.
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class Fields implements FieldsInterface
|
||||
{
|
||||
use MaxTrait;
|
||||
use NilTrait;
|
||||
use SerializableFieldsTrait;
|
||||
use VariantTrait;
|
||||
use VersionTrait;
|
||||
|
||||
/**
|
||||
* @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 9562 (formerly RFC 4122) UUID
|
||||
* @throws InvalidArgumentException if the byte string does not contain a valid version
|
||||
*/
|
||||
public function __construct(private string $bytes)
|
||||
{
|
||||
if (strlen($this->bytes) !== 16) {
|
||||
throw new InvalidArgumentException(
|
||||
'The byte string must be 16 bytes long; ' . 'received ' . strlen($this->bytes) . ' bytes',
|
||||
);
|
||||
}
|
||||
|
||||
if (!$this->isCorrectVariant()) {
|
||||
throw new InvalidArgumentException(
|
||||
'The byte string received does not conform to the RFC 9562 (formerly RFC 4122) variant',
|
||||
);
|
||||
}
|
||||
|
||||
if (!$this->isCorrectVersion()) {
|
||||
throw new InvalidArgumentException(
|
||||
'The byte string received does not contain a valid RFC 9562 (formerly RFC 4122) version',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @pure
|
||||
*/
|
||||
public function getBytes(): string
|
||||
{
|
||||
return $this->bytes;
|
||||
}
|
||||
|
||||
public function getClockSeq(): Hexadecimal
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
public function getClockSeqHiAndReserved(): Hexadecimal
|
||||
{
|
||||
return new Hexadecimal(bin2hex(substr($this->bytes, 8, 1)));
|
||||
}
|
||||
|
||||
public function getClockSeqLow(): Hexadecimal
|
||||
{
|
||||
return new Hexadecimal(bin2hex(substr($this->bytes, 9, 1)));
|
||||
}
|
||||
|
||||
public function getNode(): Hexadecimal
|
||||
{
|
||||
return new Hexadecimal(bin2hex(substr($this->bytes, 10)));
|
||||
}
|
||||
|
||||
public function getTimeHiAndVersion(): Hexadecimal
|
||||
{
|
||||
return new Hexadecimal(bin2hex(substr($this->bytes, 6, 2)));
|
||||
}
|
||||
|
||||
public function getTimeLow(): Hexadecimal
|
||||
{
|
||||
return new Hexadecimal(bin2hex(substr($this->bytes, 0, 4)));
|
||||
}
|
||||
|
||||
public function getTimeMid(): Hexadecimal
|
||||
{
|
||||
return new Hexadecimal(bin2hex(substr($this->bytes, 4, 2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full 60-bit timestamp, without the version
|
||||
*
|
||||
* For version 2 UUIDs, the time_low field is the local identifier and should not be returned as part of the time.
|
||||
* For this reason, we set the bottom 32 bits of the timestamp to 0's. As a result, there is some loss of timestamp
|
||||
* fidelity, for version 2 UUIDs. The timestamp can be off by a range of 0 to 429.4967295 seconds (or 7 minutes, 9
|
||||
* seconds, and 496,730 microseconds).
|
||||
*
|
||||
* For version 6 UUIDs, the timestamp order is reversed from the typical RFC 9562 (formerly RFC 4122) order (the
|
||||
* time bits are in the correct bit order, so that it is monotonically increasing). In returning the timestamp
|
||||
* value, we put the bits in the order: time_low + time_mid + time_hi.
|
||||
*/
|
||||
public function getTimestamp(): Hexadecimal
|
||||
{
|
||||
return new Hexadecimal(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()
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
public function getVersion(): ?int
|
||||
{
|
||||
if ($this->isNil() || $this->isMax()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var int[] $parts */
|
||||
$parts = unpack('n*', $this->bytes);
|
||||
|
||||
return $parts[4] >> 12;
|
||||
}
|
||||
|
||||
private function isCorrectVariant(): bool
|
||||
{
|
||||
if ($this->isNil() || $this->isMax()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->getVariant() === Uuid::RFC_4122;
|
||||
}
|
||||
}
|
||||
130
vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php
vendored
Normal file
130
vendor/ramsey/uuid/src/Rfc4122/FieldsInterface.php
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
<?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\Fields\FieldsInterface as BaseFieldsInterface;
|
||||
use Ramsey\Uuid\Type\Hexadecimal;
|
||||
|
||||
/**
|
||||
* UUID fields, as defined by RFC 4122
|
||||
*
|
||||
* This interface defines the fields of an RFC 4122 variant UUID. Since RFC 9562 removed the concept of fields and
|
||||
* instead defined layouts that are specific to a given version, this interface is a legacy artifact of the earlier, and
|
||||
* now obsolete, RFC 4122.
|
||||
*
|
||||
* The fields of an RFC 4122 variant UUID are:
|
||||
*
|
||||
* * **time_low**: The low field of the timestamp, an unsigned 32-bit integer
|
||||
* * **time_mid**: The middle field of the timestamp, an unsigned 16-bit integer
|
||||
* * **time_hi_and_version**: The high field of the timestamp multiplexed with the version number, an unsigned 16-bit integer
|
||||
* * **clock_seq_hi_and_reserved**: The high field of the clock sequence multiplexed with the variant, an unsigned 8-bit integer
|
||||
* * **clock_seq_low**: The low field of the clock sequence, an unsigned 8-bit integer
|
||||
* * **node**: The spatially unique node identifier, an unsigned 48-bit integer
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc4122#section-4.1 RFC 4122, 4.1. Format
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-4 RFC 9562, 4. UUID Format
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
interface FieldsInterface extends BaseFieldsInterface
|
||||
{
|
||||
/**
|
||||
* Returns the full 16-bit clock sequence, with the variant bits (two most significant bits) masked out
|
||||
*/
|
||||
public function getClockSeq(): Hexadecimal;
|
||||
|
||||
/**
|
||||
* Returns the high field of the clock sequence multiplexed with the variant
|
||||
*/
|
||||
public function getClockSeqHiAndReserved(): Hexadecimal;
|
||||
|
||||
/**
|
||||
* Returns the low field of the clock sequence
|
||||
*/
|
||||
public function getClockSeqLow(): Hexadecimal;
|
||||
|
||||
/**
|
||||
* Returns the node field
|
||||
*/
|
||||
public function getNode(): Hexadecimal;
|
||||
|
||||
/**
|
||||
* Returns the high field of the timestamp multiplexed with the version
|
||||
*/
|
||||
public function getTimeHiAndVersion(): Hexadecimal;
|
||||
|
||||
/**
|
||||
* Returns the low field of the timestamp
|
||||
*/
|
||||
public function getTimeLow(): Hexadecimal;
|
||||
|
||||
/**
|
||||
* Returns the middle field of the timestamp
|
||||
*/
|
||||
public function getTimeMid(): Hexadecimal;
|
||||
|
||||
/**
|
||||
* Returns the full 60-bit timestamp, without the version
|
||||
*/
|
||||
public function getTimestamp(): Hexadecimal;
|
||||
|
||||
/**
|
||||
* Returns the variant
|
||||
*
|
||||
* The variant number describes the layout of the UUID. The variant number has the following meaning:
|
||||
*
|
||||
* - 0 - Reserved for NCS backward compatibility
|
||||
* - 2 - The RFC 9562 (formerly RFC 4122) variant
|
||||
* - 6 - Reserved, Microsoft Corporation backward compatibility
|
||||
* - 7 - Reserved for future definition
|
||||
*
|
||||
* For RFC 9562 (formerly RFC 4122) variant UUIDs, this value should always be the integer `2`.
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-4.1 RFC 9562, 4.1. Variant Field
|
||||
*/
|
||||
public function getVariant(): int;
|
||||
|
||||
/**
|
||||
* Returns the UUID version
|
||||
*
|
||||
* The version number describes how the UUID was generated and has the following meaning:
|
||||
*
|
||||
* 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 Gregorian time UUID
|
||||
* 7. Unix Epoch time UUID
|
||||
* 8. Custom format UUID
|
||||
*
|
||||
* This returns `null` if the UUID is not an RFC 9562 (formerly RFC 4122) variant, since the version is only
|
||||
* meaningful for this variant.
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-4.2 RFC 9562, 4.2. Version Field
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
public function getVersion(): ?int;
|
||||
|
||||
/**
|
||||
* Returns true if these fields represent a nil UUID
|
||||
*
|
||||
* The nil UUID is a special form of UUID that is specified to have all 128 bits set to zero.
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
public function isNil(): bool;
|
||||
}
|
||||
40
vendor/ramsey/uuid/src/Rfc4122/MaxTrait.php
vendored
Normal file
40
vendor/ramsey/uuid/src/Rfc4122/MaxTrait.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
trait MaxTrait
|
||||
{
|
||||
/**
|
||||
* Returns the bytes that comprise the fields
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
abstract public function getBytes(): string;
|
||||
|
||||
/**
|
||||
* Returns true if the byte string represents a max UUID
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
public function isMax(): bool
|
||||
{
|
||||
return $this->getBytes() === "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
|
||||
}
|
||||
}
|
||||
28
vendor/ramsey/uuid/src/Rfc4122/MaxUuid.php
vendored
Normal file
28
vendor/ramsey/uuid/src/Rfc4122/MaxUuid.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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 a special form of UUID that has all 128 bits set to one (`1`)
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.10 RFC 9562, 5.10. Max UUID
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class MaxUuid extends Uuid implements UuidInterface
|
||||
{
|
||||
}
|
||||
38
vendor/ramsey/uuid/src/Rfc4122/NilTrait.php
vendored
Normal file
38
vendor/ramsey/uuid/src/Rfc4122/NilTrait.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 nil UUIDs
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
trait NilTrait
|
||||
{
|
||||
/**
|
||||
* Returns the bytes that comprise the fields
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
abstract public function getBytes(): string;
|
||||
|
||||
/**
|
||||
* Returns true if the byte string represents a nil UUID
|
||||
*/
|
||||
public function isNil(): bool
|
||||
{
|
||||
return $this->getBytes() === "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
}
|
||||
}
|
||||
28
vendor/ramsey/uuid/src/Rfc4122/NilUuid.php
vendored
Normal file
28
vendor/ramsey/uuid/src/Rfc4122/NilUuid.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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 nil UUID is a special form of UUID that has all 128 bits set to zero (`0`)
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.9 RFC 9562, 5.9. Nil UUID
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class NilUuid extends Uuid implements UuidInterface
|
||||
{
|
||||
}
|
||||
53
vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php
vendored
Normal file
53
vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
||||
122
vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php
vendored
Normal file
122
vendor/ramsey/uuid/src/Rfc4122/UuidBuilder.php
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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\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\Rfc4122\UuidInterface as Rfc4122UuidInterface;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* UuidBuilder builds instances of RFC 9562 (formerly 4122) UUIDs
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
class UuidBuilder implements UuidBuilderInterface
|
||||
{
|
||||
private TimeConverterInterface $unixTimeConverter;
|
||||
|
||||
/**
|
||||
* Constructs the DefaultUuidBuilder
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function __construct(
|
||||
private NumberConverterInterface $numberConverter,
|
||||
private TimeConverterInterface $timeConverter,
|
||||
?TimeConverterInterface $unixTimeConverter = null,
|
||||
) {
|
||||
$this->unixTimeConverter = $unixTimeConverter ?? new UnixTimeConverter(new BrickMathCalculator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a Uuid
|
||||
*
|
||||
* @param CodecInterface $codec The codec to use for building this Uuid instance
|
||||
* @param string $bytes The byte string from which to construct a UUID
|
||||
*
|
||||
* @return Rfc4122UuidInterface UuidBuilder returns instances of Rfc4122UuidInterface
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
public function build(CodecInterface $codec, string $bytes): UuidInterface
|
||||
{
|
||||
try {
|
||||
/** @var Fields $fields */
|
||||
$fields = $this->buildFields($bytes);
|
||||
|
||||
if ($fields->isNil()) {
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
return new NilUuid($fields, $this->numberConverter, $codec, $this->timeConverter);
|
||||
}
|
||||
|
||||
if ($fields->isMax()) {
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
return new MaxUuid($fields, $this->numberConverter, $codec, $this->timeConverter);
|
||||
}
|
||||
|
||||
return match ($fields->getVersion()) {
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
Uuid::UUID_TYPE_TIME => new UuidV1($fields, $this->numberConverter, $codec, $this->timeConverter),
|
||||
Uuid::UUID_TYPE_DCE_SECURITY
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
=> new UuidV2($fields, $this->numberConverter, $codec, $this->timeConverter),
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
Uuid::UUID_TYPE_HASH_MD5 => new UuidV3($fields, $this->numberConverter, $codec, $this->timeConverter),
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
Uuid::UUID_TYPE_RANDOM => new UuidV4($fields, $this->numberConverter, $codec, $this->timeConverter),
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
Uuid::UUID_TYPE_HASH_SHA1 => new UuidV5($fields, $this->numberConverter, $codec, $this->timeConverter),
|
||||
Uuid::UUID_TYPE_REORDERED_TIME
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
=> new UuidV6($fields, $this->numberConverter, $codec, $this->timeConverter),
|
||||
Uuid::UUID_TYPE_UNIX_TIME
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
=> new UuidV7($fields, $this->numberConverter, $codec, $this->unixTimeConverter),
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
Uuid::UUID_TYPE_CUSTOM => new UuidV8($fields, $this->numberConverter, $codec, $this->timeConverter),
|
||||
default => throw new UnsupportedOperationException(
|
||||
'The UUID version in the given fields is not supported by this UUID builder',
|
||||
),
|
||||
};
|
||||
} catch (Throwable $e) {
|
||||
/** @phpstan-ignore possiblyImpure.methodCall, possiblyImpure.methodCall */
|
||||
throw new UnableToBuildUuidException($e->getMessage(), (int) $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy method to allow injecting a mock for testing
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
protected function buildFields(string $bytes): FieldsInterface
|
||||
{
|
||||
/** @phpstan-ignore possiblyImpure.new */
|
||||
return new Fields($bytes);
|
||||
}
|
||||
}
|
||||
28
vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php
vendored
Normal file
28
vendor/ramsey/uuid/src/Rfc4122/UuidInterface.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\UuidInterface as BaseUuidInterface;
|
||||
|
||||
/**
|
||||
* A universally unique identifier (UUID), as defined in RFC 9562 (formerly RFC 4122)
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562 RFC 9562
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
interface UuidInterface extends BaseUuidInterface
|
||||
{
|
||||
}
|
||||
58
vendor/ramsey/uuid/src/Rfc4122/UuidV1.php
vendored
Normal file
58
vendor/ramsey/uuid/src/Rfc4122/UuidV1.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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, combined into a 128-bit unsigned integer
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.1 RFC 9562, 5.1. UUID Version 1
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class UuidV1 extends Uuid implements UuidInterface
|
||||
{
|
||||
use TimeTrait;
|
||||
|
||||
/**
|
||||
* 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 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_TIME) {
|
||||
throw new InvalidArgumentException(
|
||||
'Fields used to create a UuidV1 must represent a version 1 (time-based) UUID',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($fields, $numberConverter, $codec, $timeConverter);
|
||||
}
|
||||
}
|
||||
107
vendor/ramsey/uuid/src/Rfc4122/UuidV2.php
vendored
Normal file
107
vendor/ramsey/uuid/src/Rfc4122/UuidV2.php
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
<?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\Type\Integer as IntegerObject;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use function hexdec;
|
||||
|
||||
/**
|
||||
* 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 timestamp fidelity, 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 496,730 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://www.rfc-editor.org/rfc/rfc9562#section-5.2 RFC 9562, 5.2. UUID Version 2
|
||||
* @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
|
||||
* @link https://pubs.opengroup.org/onlinepubs/9696989899/chap11.htm#tagcjh_14_05_01_01 DCE 1.1: Auth & Sec, §11.5.1.1
|
||||
* @link https://pubs.opengroup.org/onlinepubs/9629399/apdxa.htm DCE 1.1: RPC, Appendix A
|
||||
* @link https://github.com/google/uuid Go package for UUIDs (includes DCE implementation)
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class UuidV2 extends Uuid implements UuidInterface
|
||||
{
|
||||
use TimeTrait;
|
||||
|
||||
/**
|
||||
* Creates a version 2 (DCE Security) 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_DCE_SECURITY) {
|
||||
throw new InvalidArgumentException(
|
||||
'Fields used to create a UuidV2 must represent a version 2 (DCE Security) UUID'
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($fields, $numberConverter, $codec, $timeConverter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local domain used to create this version 2 UUID
|
||||
*/
|
||||
public function getLocalDomain(): int
|
||||
{
|
||||
/** @var Rfc4122FieldsInterface $fields */
|
||||
$fields = $this->getFields();
|
||||
|
||||
return (int) hexdec($fields->getClockSeqLow()->toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string name of the local domain
|
||||
*/
|
||||
public function getLocalDomainName(): string
|
||||
{
|
||||
return Uuid::DCE_DOMAIN_NAMES[$this->getLocalDomain()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local identifier for the domain used to create this version 2 UUID
|
||||
*/
|
||||
public function getLocalIdentifier(): IntegerObject
|
||||
{
|
||||
/** @var Rfc4122FieldsInterface $fields */
|
||||
$fields = $this->getFields();
|
||||
|
||||
return new IntegerObject($this->numberConverter->fromHex($fields->getTimeLow()->toString()));
|
||||
}
|
||||
}
|
||||
57
vendor/ramsey/uuid/src/Rfc4122/UuidV3.php
vendored
Normal file
57
vendor/ramsey/uuid/src/Rfc4122/UuidV3.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Version 3 UUIDs are named-based, using a combination of a namespace and name that are hashed into a 128-bit unsigned
|
||||
* integer using the MD5 hashing algorithm
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.3 RFC 9562, 5.3. UUID Version 3
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class UuidV3 extends Uuid implements UuidInterface
|
||||
{
|
||||
/**
|
||||
* Creates a version 3 (name-based, MD5-hashed) 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_HASH_MD5) {
|
||||
throw new InvalidArgumentException(
|
||||
'Fields used to create a UuidV3 must represent a version 3 (name-based, MD5-hashed) UUID',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($fields, $numberConverter, $codec, $timeConverter);
|
||||
}
|
||||
}
|
||||
56
vendor/ramsey/uuid/src/Rfc4122/UuidV4.php
vendored
Normal file
56
vendor/ramsey/uuid/src/Rfc4122/UuidV4.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Random, or version 4, UUIDs are randomly or pseudo-randomly generated 128-bit integers
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.4 RFC 9562, 5.4. UUID Version 4
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class UuidV4 extends Uuid implements UuidInterface
|
||||
{
|
||||
/**
|
||||
* Creates a version 4 (random) 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_RANDOM) {
|
||||
throw new InvalidArgumentException(
|
||||
'Fields used to create a UuidV4 must represent a version 4 (random) UUID',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($fields, $numberConverter, $codec, $timeConverter);
|
||||
}
|
||||
}
|
||||
57
vendor/ramsey/uuid/src/Rfc4122/UuidV5.php
vendored
Normal file
57
vendor/ramsey/uuid/src/Rfc4122/UuidV5.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Version 5 UUIDs are named-based, using a combination of a namespace and name that are hashed into a 128-bit unsigned
|
||||
* integer using the SHA1 hashing algorithm
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.5 RFC 9562, 5.5. UUID Version 5
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class UuidV5 extends Uuid implements UuidInterface
|
||||
{
|
||||
/**
|
||||
* Creates a version 5 (name-based, SHA1-hashed) 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_HASH_SHA1) {
|
||||
throw new InvalidArgumentException(
|
||||
'Fields used to create a UuidV5 must represent a version 5 (named-based, SHA1-hashed) UUID',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($fields, $numberConverter, $codec, $timeConverter);
|
||||
}
|
||||
}
|
||||
29
vendor/ramsey/uuid/src/Rfc4122/UuidV6.php
vendored
Normal file
29
vendor/ramsey/uuid/src/Rfc4122/UuidV6.php
vendored
Normal file
@@ -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 Gregorian time, or version 6, UUIDs include timestamp, clock sequence, and node values that are combined
|
||||
* into a 128-bit unsigned integer
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.6 RFC 9562, 5.6. UUID Version 6
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class UuidV6 extends NonstandardUuidV6 implements UuidInterface
|
||||
{
|
||||
}
|
||||
58
vendor/ramsey/uuid/src/Rfc4122/UuidV7.php
vendored
Normal file
58
vendor/ramsey/uuid/src/Rfc4122/UuidV7.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Unix Epoch time, or version 7, UUIDs include a timestamp in milliseconds since the Unix Epoch, along with random bytes
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.7 RFC 9562, 5.7. UUID Version 7
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
60
vendor/ramsey/uuid/src/Rfc4122/UuidV8.php
vendored
Normal file
60
vendor/ramsey/uuid/src/Rfc4122/UuidV8.php
vendored
Normal file
@@ -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;
|
||||
|
||||
/**
|
||||
* Custom format, or version 8, UUIDs provide an RFC-compatible format for experimental or vendor-specific uses
|
||||
*
|
||||
* The only requirement for version 8 UUIDs is that the version and variant bits must be set. Otherwise, implementations
|
||||
* are free to set the other bits according to their needs. As a result, the uniqueness of version 8 UUIDs is
|
||||
* implementation-specific and should not be assumed.
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-5.8 RFC 9562, 5.8. UUID Version 8
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class UuidV8 extends Uuid implements UuidInterface
|
||||
{
|
||||
/**
|
||||
* Creates a version 8 (custom format) 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_CUSTOM) {
|
||||
throw new InvalidArgumentException(
|
||||
'Fields used to create a UuidV8 must represent a version 8 (custom format) UUID',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($fields, $numberConverter, $codec, $timeConverter);
|
||||
}
|
||||
}
|
||||
49
vendor/ramsey/uuid/src/Rfc4122/Validator.php
vendored
Normal file
49
vendor/ramsey/uuid/src/Rfc4122/Validator.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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;
|
||||
use Ramsey\Uuid\Validator\ValidatorInterface;
|
||||
|
||||
use function preg_match;
|
||||
use function str_replace;
|
||||
|
||||
/**
|
||||
* Rfc4122\Validator validates strings as UUIDs of the RFC 9562 (formerly RFC 4122) variant
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
final class Validator implements ValidatorInterface
|
||||
{
|
||||
private const VALID_PATTERN = '\A[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-'
|
||||
. '[1-8][0-9A-Fa-f]{3}-[ABab89][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}\z';
|
||||
|
||||
/**
|
||||
* @return non-empty-string
|
||||
*/
|
||||
public function getPattern(): string
|
||||
{
|
||||
return self::VALID_PATTERN;
|
||||
}
|
||||
|
||||
public function validate(string $uuid): bool
|
||||
{
|
||||
/** @phpstan-ignore possiblyImpure.functionCall */
|
||||
$uuid = strtolower(str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid));
|
||||
|
||||
/** @phpstan-ignore possiblyImpure.functionCall */
|
||||
return $uuid === Uuid::NIL || $uuid === Uuid::MAX || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid);
|
||||
}
|
||||
}
|
||||
93
vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php
vendored
Normal file
93
vendor/ramsey/uuid/src/Rfc4122/VariantTrait.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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\Exception\InvalidBytesException;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use function decbin;
|
||||
use function str_pad;
|
||||
use function str_starts_with;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use function unpack;
|
||||
|
||||
use const STR_PAD_LEFT;
|
||||
|
||||
/**
|
||||
* Provides common functionality for handling the variant, as defined by RFC 9562 (formerly RFC 4122)
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
trait VariantTrait
|
||||
{
|
||||
/**
|
||||
* Returns the bytes that comprise the fields
|
||||
*/
|
||||
abstract public function getBytes(): string;
|
||||
|
||||
/**
|
||||
* Returns the variant
|
||||
*
|
||||
* The variant number describes the layout of the UUID. The variant number has the following meaning:
|
||||
*
|
||||
* - 0 - Reserved for NCS backward compatibility
|
||||
* - 2 - The RFC 9562 (formerly RFC 4122) variant
|
||||
* - 6 - Reserved, Microsoft Corporation backward compatibility
|
||||
* - 7 - Reserved for future definition
|
||||
*
|
||||
* For RFC 9562 (formerly RFC 4122) variant UUIDs, this value should always be the integer `2`.
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-4.1 RFC 9562, 4.1. Variant Field
|
||||
*/
|
||||
public function getVariant(): int
|
||||
{
|
||||
if (strlen($this->getBytes()) !== 16) {
|
||||
throw new InvalidBytesException('Invalid number of bytes');
|
||||
}
|
||||
|
||||
// According to RFC 9562, sections {@link https://www.rfc-editor.org/rfc/rfc9562#section-4.1 4.1} and
|
||||
// {@link https://www.rfc-editor.org/rfc/rfc9562#section-5.10 5.10}, the Max UUID falls within the range
|
||||
// of the future variant.
|
||||
if ($this->isMax()) {
|
||||
return Uuid::RESERVED_FUTURE;
|
||||
}
|
||||
|
||||
// According to RFC 9562, sections {@link https://www.rfc-editor.org/rfc/rfc9562#section-4.1 4.1} and
|
||||
// {@link https://www.rfc-editor.org/rfc/rfc9562#section-5.9 5.9}, the Nil UUID falls within the range
|
||||
// of the Apollo NCS variant.
|
||||
if ($this->isNil()) {
|
||||
return Uuid::RESERVED_NCS;
|
||||
}
|
||||
|
||||
/** @var int[] $parts */
|
||||
$parts = unpack('n*', $this->getBytes());
|
||||
|
||||
// $parts[5] is a 16-bit, unsigned integer containing the variant bits of the UUID. We convert this integer into
|
||||
// a string containing a binary representation, padded to 16 characters. We analyze the first three characters
|
||||
// (three most-significant bits) to determine the variant.
|
||||
$msb = substr(str_pad(decbin($parts[5]), 16, '0', STR_PAD_LEFT), 0, 3);
|
||||
|
||||
if ($msb === '111') {
|
||||
return Uuid::RESERVED_FUTURE;
|
||||
} elseif ($msb === '110') {
|
||||
return Uuid::RESERVED_MICROSOFT;
|
||||
} elseif (str_starts_with($msb, '10')) {
|
||||
return Uuid::RFC_4122;
|
||||
}
|
||||
|
||||
return Uuid::RESERVED_NCS;
|
||||
}
|
||||
}
|
||||
78
vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php
vendored
Normal file
78
vendor/ramsey/uuid/src/Rfc4122/VersionTrait.php
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Provides common functionality for handling the version, as defined by RFC 9562 (formerly RFC 4122)
|
||||
*
|
||||
* @immutable
|
||||
*/
|
||||
trait VersionTrait
|
||||
{
|
||||
/**
|
||||
* Returns the UUID version
|
||||
*
|
||||
* The version number describes how the UUID was generated and has the following meaning:
|
||||
*
|
||||
* 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 Gregorian time UUID
|
||||
* 7. Unix Epoch time UUID
|
||||
* 8. Custom format UUID
|
||||
*
|
||||
* This returns `null` if the UUID is not an RFC 9562 (formerly RFC 4122) variant, since the version is only
|
||||
* meaningful for this variant.
|
||||
*
|
||||
* @link https://www.rfc-editor.org/rfc/rfc9562#section-4.2 RFC 9562, 4.2. Version Field
|
||||
*
|
||||
* @pure
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Returns true if the version matches one of those defined by RFC 9562 (formerly RFC 4122)
|
||||
*
|
||||
* @return bool True if the UUID version is valid, false otherwise
|
||||
*/
|
||||
private function isCorrectVersion(): bool
|
||||
{
|
||||
if ($this->isNil() || $this->isMax()) {
|
||||
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, Uuid::UUID_TYPE_CUSTOM => true,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user