diff options
Diffstat (limited to 'vendor/ramsey/uuid/src')
55 files changed, 996 insertions, 907 deletions
diff --git a/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php index 23931e416..20b384212 100644 --- a/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php +++ b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php @@ -30,15 +30,7 @@ use Ramsey\Uuid\UuidInterface; */ class DegradedUuidBuilder implements UuidBuilderInterface { - /** - * @var NumberConverterInterface - */ - private $numberConverter; - - /** - * @var TimeConverterInterface - */ - private $timeConverter; + private TimeConverterInterface $timeConverter; /** * @param NumberConverterInterface $numberConverter The number converter to @@ -47,10 +39,9 @@ class DegradedUuidBuilder implements UuidBuilderInterface * for converting timestamps extracted from a UUID to Unix timestamps */ public function __construct( - NumberConverterInterface $numberConverter, + private NumberConverterInterface $numberConverter, ?TimeConverterInterface $timeConverter = null ) { - $this->numberConverter = $numberConverter; $this->timeConverter = $timeConverter ?: new DegradedTimeConverter(); } diff --git a/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php b/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php index 8ab438a19..ba5f31fbe 100644 --- a/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php +++ b/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php @@ -28,16 +28,10 @@ use Ramsey\Uuid\UuidInterface; class FallbackBuilder implements UuidBuilderInterface { /** - * @var iterable<UuidBuilderInterface> - */ - private $builders; - - /** * @param iterable<UuidBuilderInterface> $builders An array of UUID builders */ - public function __construct(iterable $builders) + public function __construct(private iterable $builders) { - $this->builders = $builders; } /** diff --git a/vendor/ramsey/uuid/src/Codec/StringCodec.php b/vendor/ramsey/uuid/src/Codec/StringCodec.php index 58c9f5806..4b6e4e5b9 100644 --- a/vendor/ramsey/uuid/src/Codec/StringCodec.php +++ b/vendor/ramsey/uuid/src/Codec/StringCodec.php @@ -37,18 +37,12 @@ use function substr; class StringCodec implements CodecInterface { /** - * @var UuidBuilderInterface - */ - private $builder; - - /** * Constructs a StringCodec * * @param UuidBuilderInterface $builder The builder to use when encoding UUIDs */ - public function __construct(UuidBuilderInterface $builder) + public function __construct(private UuidBuilderInterface $builder) { - $this->builder = $builder; } public function encode(UuidInterface $uuid): string diff --git a/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php index fef63fd00..99b88b3bf 100644 --- a/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php +++ b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php @@ -27,10 +27,7 @@ use Ramsey\Uuid\Math\BrickMathCalculator; */ class BigNumberConverter implements NumberConverterInterface { - /** - * @var NumberConverterInterface - */ - private $converter; + private NumberConverterInterface $converter; public function __construct() { diff --git a/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php index 501eac0fa..043c3c43d 100644 --- a/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php +++ b/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php @@ -26,14 +26,8 @@ use Ramsey\Uuid\Type\Integer as IntegerObject; */ class GenericNumberConverter implements NumberConverterInterface { - /** - * @var CalculatorInterface - */ - private $calculator; - - public function __construct(CalculatorInterface $calculator) + public function __construct(private CalculatorInterface $calculator) { - $this->calculator = $calculator; } /** diff --git a/vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php b/vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php index 7390dad83..b6bca9ee2 100644 --- a/vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php +++ b/vendor/ramsey/uuid/src/Converter/Time/BigNumberTimeConverter.php @@ -29,10 +29,7 @@ use Ramsey\Uuid\Type\Time; */ class BigNumberTimeConverter implements TimeConverterInterface { - /** - * @var TimeConverterInterface - */ - private $converter; + private TimeConverterInterface $converter; public function __construct() { diff --git a/vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php b/vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php index a8aa64b73..f6b60abbe 100644 --- a/vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php +++ b/vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php @@ -50,14 +50,8 @@ class GenericTimeConverter implements TimeConverterInterface */ private const MICROSECOND_INTERVALS = '10'; - /** - * @var CalculatorInterface - */ - private $calculator; - - public function __construct(CalculatorInterface $calculator) + public function __construct(private CalculatorInterface $calculator) { - $this->calculator = $calculator; } public function calculateTime(string $seconds, string $microseconds): Hexadecimal diff --git a/vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php b/vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php index 538d2f2f6..66009f14d 100644 --- a/vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php +++ b/vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php @@ -58,20 +58,9 @@ class PhpTimeConverter implements TimeConverterInterface */ private const MICROSECOND_INTERVALS = 10; - /** - * @var CalculatorInterface - */ - private $calculator; - - /** - * @var TimeConverterInterface - */ - private $fallbackConverter; - - /** - * @var int - */ - private $phpPrecision; + private int $phpPrecision; + private CalculatorInterface $calculator; + private TimeConverterInterface $fallbackConverter; public function __construct( ?CalculatorInterface $calculator = null, @@ -132,11 +121,11 @@ class PhpTimeConverter implements TimeConverterInterface } /** - * @param int|float $time The time to split into seconds and microseconds + * @param float|int $time The time to split into seconds and microseconds * * @return string[] */ - private function splitTime($time): array + private function splitTime(float | int $time): array { $split = explode('.', (string) $time, 2); diff --git a/vendor/ramsey/uuid/src/Converter/Time/UnixTimeConverter.php b/vendor/ramsey/uuid/src/Converter/Time/UnixTimeConverter.php new file mode 100644 index 000000000..4d6d0a8a7 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Time/UnixTimeConverter.php @@ -0,0 +1,90 @@ +<?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\Converter\Time; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Math\CalculatorInterface; +use Ramsey\Uuid\Math\RoundingMode; +use Ramsey\Uuid\Type\Hexadecimal; +use Ramsey\Uuid\Type\Integer as IntegerObject; +use Ramsey\Uuid\Type\Time; + +use function explode; +use function str_pad; + +use const STR_PAD_LEFT; + +/** + * UnixTimeConverter converts Unix Epoch timestamps to/from hexadecimal values + * consisting of milliseconds elapsed since the Unix Epoch + * + * @psalm-immutable + */ +class UnixTimeConverter implements TimeConverterInterface +{ + private const MILLISECONDS = 1000; + + public function __construct(private CalculatorInterface $calculator) + { + } + + public function calculateTime(string $seconds, string $microseconds): Hexadecimal + { + $timestamp = new Time($seconds, $microseconds); + + // Convert the seconds into milliseconds. + $sec = $this->calculator->multiply( + $timestamp->getSeconds(), + new IntegerObject(self::MILLISECONDS), + ); + + // Convert the microseconds into milliseconds; the scale is zero because + // we need to discard the fractional part. + $usec = $this->calculator->divide( + RoundingMode::DOWN, // Always round down to stay in the previous millisecond. + 0, + $timestamp->getMicroseconds(), + new IntegerObject(self::MILLISECONDS), + ); + + /** @var IntegerObject $unixTime */ + $unixTime = $this->calculator->add($sec, $usec); + + $unixTimeHex = str_pad( + $this->calculator->toHexadecimal($unixTime)->toString(), + 12, + '0', + STR_PAD_LEFT + ); + + return new Hexadecimal($unixTimeHex); + } + + public function convertTime(Hexadecimal $uuidTimestamp): Time + { + $milliseconds = $this->calculator->toInteger($uuidTimestamp); + + $unixTimestamp = $this->calculator->divide( + RoundingMode::HALF_UP, + 6, + $milliseconds, + new IntegerObject(self::MILLISECONDS) + ); + + $split = explode('.', (string) $unixTimestamp, 2); + + return new Time($split[0], $split[1] ?? '0'); + } +} diff --git a/vendor/ramsey/uuid/src/DeprecatedUuidInterface.php b/vendor/ramsey/uuid/src/DeprecatedUuidInterface.php index ed6d9dec8..ac01a79cf 100644 --- a/vendor/ramsey/uuid/src/DeprecatedUuidInterface.php +++ b/vendor/ramsey/uuid/src/DeprecatedUuidInterface.php @@ -18,8 +18,7 @@ use DateTimeInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; /** - * This interface encapsulates deprecated methods for ramsey/uuid; this - * interface and its methods will be removed in ramsey/uuid 5.0.0. + * This interface encapsulates deprecated methods for ramsey/uuid * * @psalm-immutable */ @@ -124,12 +123,6 @@ interface DeprecatedUuidInterface public function getTimestampHex(): string; /** - * @deprecated In ramsey/uuid version 5.0.0, this will be removed from this - * interface. It has moved to {@see \Ramsey\Uuid\Rfc4122\UuidInterface::getUrn()}. - */ - public function getUrn(): string; - - /** * @deprecated Use {@see UuidInterface::getFields()} to get a * {@see FieldsInterface} instance. If it is a * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call diff --git a/vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php b/vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php index 342829523..d3fbb0ccb 100644 --- a/vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php +++ b/vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php @@ -17,10 +17,8 @@ namespace Ramsey\Uuid; use DateTimeImmutable; use DateTimeInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; -use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\Exception\DateTimeException; use Ramsey\Uuid\Exception\UnsupportedOperationException; -use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; use Throwable; use function str_pad; @@ -32,29 +30,17 @@ use const STR_PAD_LEFT; * This trait encapsulates deprecated methods for ramsey/uuid; this trait and * its methods will be removed in ramsey/uuid 5.0.0. * + * @deprecated This trait and its methods will be removed in ramsey/uuid 5.0.0. + * * @psalm-immutable */ trait DeprecatedUuidMethodsTrait { /** - * @var Rfc4122FieldsInterface - */ - protected $fields; - - /** - * @var NumberConverterInterface - */ - protected $numberConverter; - - /** - * @var TimeConverterInterface - */ - protected $timeConverter; - - /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqHiAndReserved()} + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqHiAndReserved()} * and use the arbitrary-precision math library of your choice to * convert it to a string integer. */ @@ -65,8 +51,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqHiAndReserved()}. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqHiAndReserved()}. */ public function getClockSeqHiAndReservedHex(): string { @@ -75,8 +62,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqLow()} + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqLow()} * and use the arbitrary-precision math library of your choice to * convert it to a string integer. */ @@ -87,8 +75,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqLow()}. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqLow()}. */ public function getClockSeqLowHex(): string { @@ -97,8 +86,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeq()} + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeq()} * and use the arbitrary-precision math library of your choice to * convert it to a string integer. */ @@ -109,8 +99,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeq()}. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeq()}. */ public function getClockSequenceHex(): string { @@ -157,7 +148,7 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. * * @return string[] */ @@ -219,10 +210,11 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getNode()} - * and use the arbitrary-precision math library of your choice to - * convert it to a string integer. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getNode()} and use the + * arbitrary-precision math library of your choice to convert it to a + * string integer. */ public function getNode(): string { @@ -231,8 +223,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getNode()}. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getNode()}. */ public function getNodeHex(): string { @@ -241,8 +234,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimeHiAndVersion()} + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeHiAndVersion()} * and use the arbitrary-precision math library of your choice to * convert it to a string integer. */ @@ -253,8 +247,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimeHiAndVersion()}. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeHiAndVersion()}. */ public function getTimeHiAndVersionHex(): string { @@ -263,10 +258,11 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimeLow()} - * and use the arbitrary-precision math library of your choice to - * convert it to a string integer. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeLow()} and use the + * arbitrary-precision math library of your choice to convert it to a + * string integer. */ public function getTimeLow(): string { @@ -275,8 +271,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimeLow()}. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeLow()}. */ public function getTimeLowHex(): string { @@ -285,10 +282,11 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimeMid()} - * and use the arbitrary-precision math library of your choice to - * convert it to a string integer. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeMid()} and use the + * arbitrary-precision math library of your choice to convert it to a + * string integer. */ public function getTimeMid(): string { @@ -297,8 +295,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimeMid()}. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeMid()}. */ public function getTimeMidHex(): string { @@ -307,10 +306,11 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()} - * and use the arbitrary-precision math library of your choice to - * convert it to a string integer. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimestamp()} and use + * the arbitrary-precision math library of your choice to convert it to + * a string integer. */ public function getTimestamp(): string { @@ -323,8 +323,9 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()}. + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call + * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimestamp()}. */ public function getTimestampHex(): string { @@ -336,19 +337,8 @@ trait DeprecatedUuidMethodsTrait } /** - * @deprecated This has moved to {@see Rfc4122FieldsInterface::getUrn()} and - * is available on {@see \Ramsey\Uuid\Rfc4122\UuidV1}, - * {@see \Ramsey\Uuid\Rfc4122\UuidV3}, {@see \Ramsey\Uuid\Rfc4122\UuidV4}, - * and {@see \Ramsey\Uuid\Rfc4122\UuidV5}. - */ - public function getUrn(): string - { - return 'urn:uuid:' . $this->toString(); - } - - /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVariant()}. */ @@ -359,7 +349,7 @@ trait DeprecatedUuidMethodsTrait /** * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a + * {@see \Ramsey\Uuid\Fields\FieldsInterface} instance. If it is a * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVersion()}. */ diff --git a/vendor/ramsey/uuid/src/FeatureSet.php b/vendor/ramsey/uuid/src/FeatureSet.php index 668366601..6c8ccb0de 100644 --- a/vendor/ramsey/uuid/src/FeatureSet.php +++ b/vendor/ramsey/uuid/src/FeatureSet.php @@ -23,6 +23,7 @@ use Ramsey\Uuid\Converter\Number\GenericNumberConverter; use Ramsey\Uuid\Converter\NumberConverterInterface; use Ramsey\Uuid\Converter\Time\GenericTimeConverter; use Ramsey\Uuid\Converter\Time\PhpTimeConverter; +use Ramsey\Uuid\Converter\Time\UnixTimeConverter; use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\Generator\DceSecurityGenerator; use Ramsey\Uuid\Generator\DceSecurityGeneratorInterface; @@ -35,6 +36,7 @@ use Ramsey\Uuid\Generator\RandomGeneratorFactory; use Ramsey\Uuid\Generator\RandomGeneratorInterface; use Ramsey\Uuid\Generator\TimeGeneratorFactory; use Ramsey\Uuid\Generator\TimeGeneratorInterface; +use Ramsey\Uuid\Generator\UnixTimeGenerator; use Ramsey\Uuid\Guid\GuidBuilder; use Ramsey\Uuid\Math\BrickMathCalculator; use Ramsey\Uuid\Math\CalculatorInterface; @@ -61,92 +63,25 @@ use const PHP_INT_SIZE; */ class FeatureSet { - /** - * @var bool - */ - private $disableBigNumber = false; - - /** - * @var bool - */ - private $disable64Bit = false; - - /** - * @var bool - */ - private $ignoreSystemNode = false; - - /** - * @var bool - */ - private $enablePecl = false; - - /** - * @var UuidBuilderInterface - */ - private $builder; - - /** - * @var CodecInterface - */ - private $codec; - - /** - * @var DceSecurityGeneratorInterface - */ - private $dceSecurityGenerator; - - /** - * @var NameGeneratorInterface - */ - private $nameGenerator; - - /** - * @var NodeProviderInterface - */ - private $nodeProvider; - - /** - * @var NumberConverterInterface - */ - private $numberConverter; - - /** - * @var TimeConverterInterface - */ - private $timeConverter; - - /** - * @var RandomGeneratorInterface - */ - private $randomGenerator; - - /** - * @var TimeGeneratorInterface - */ - private $timeGenerator; - - /** - * @var TimeProviderInterface - */ - private $timeProvider; - - /** - * @var ValidatorInterface - */ - private $validator; - - /** - * @var CalculatorInterface - */ - private $calculator; + private ?TimeProviderInterface $timeProvider = null; + private CalculatorInterface $calculator; + private CodecInterface $codec; + private DceSecurityGeneratorInterface $dceSecurityGenerator; + private NameGeneratorInterface $nameGenerator; + private NodeProviderInterface $nodeProvider; + private NumberConverterInterface $numberConverter; + private RandomGeneratorInterface $randomGenerator; + private TimeConverterInterface $timeConverter; + private TimeGeneratorInterface $timeGenerator; + private TimeGeneratorInterface $unixTimeGenerator; + private UuidBuilderInterface $builder; + private ValidatorInterface $validator; /** * @param bool $useGuids True build UUIDs using the GuidStringCodec * @param bool $force32Bit True to force the use of 32-bit functionality * (primarily for testing purposes) - * @param bool $forceNoBigNumber True to disable the use of moontoast/math - * (primarily for testing purposes) + * @param bool $forceNoBigNumber (obsolete) * @param bool $ignoreSystemNode True to disable attempts to check for the * system node ID (primarily for testing purposes) * @param bool $enablePecl True to enable the use of the PeclUuidTimeGenerator @@ -154,25 +89,23 @@ class FeatureSet */ public function __construct( bool $useGuids = false, - bool $force32Bit = false, + private bool $force32Bit = false, bool $forceNoBigNumber = false, - bool $ignoreSystemNode = false, - bool $enablePecl = false + private bool $ignoreSystemNode = false, + private bool $enablePecl = false ) { - $this->disableBigNumber = $forceNoBigNumber; - $this->disable64Bit = $force32Bit; - $this->ignoreSystemNode = $ignoreSystemNode; - $this->enablePecl = $enablePecl; - + $this->randomGenerator = $this->buildRandomGenerator(); $this->setCalculator(new BrickMathCalculator()); $this->builder = $this->buildUuidBuilder($useGuids); $this->codec = $this->buildCodec($useGuids); $this->nodeProvider = $this->buildNodeProvider(); $this->nameGenerator = $this->buildNameGenerator(); - $this->randomGenerator = $this->buildRandomGenerator(); $this->setTimeProvider(new SystemTimeProvider()); $this->setDceSecurityProvider(new SystemDceSecurityProvider()); $this->validator = new GenericValidator(); + + assert($this->timeProvider !== null); + $this->unixTimeGenerator = $this->buildUnixTimeGenerator($this->timeProvider); } /** @@ -256,6 +189,14 @@ class FeatureSet } /** + * Returns the Unix Epoch time generator configured for this environment + */ + public function getUnixTimeGenerator(): TimeGeneratorInterface + { + return $this->unixTimeGenerator; + } + + /** * Returns the validator configured for this environment */ public function getValidator(): ValidatorInterface @@ -292,7 +233,10 @@ class FeatureSet public function setNodeProvider(NodeProviderInterface $nodeProvider): void { $this->nodeProvider = $nodeProvider; - $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider); + + if (isset($this->timeProvider)) { + $this->timeGenerator = $this->buildTimeGenerator($this->timeProvider); + } } /** @@ -394,6 +338,21 @@ class FeatureSet } /** + * Returns a Unix Epoch time generator configured for this environment + * + * @param TimeProviderInterface $timeProvider The time provider to use with + * the time generator + */ + private function buildUnixTimeGenerator(TimeProviderInterface $timeProvider): TimeGeneratorInterface + { + return new UnixTimeGenerator( + new UnixTimeConverter(new BrickMathCalculator()), + $timeProvider, + $this->randomGenerator, + ); + } + + /** * Returns a name generator configured for this environment */ private function buildNameGenerator(): NameGeneratorInterface @@ -441,6 +400,6 @@ class FeatureSet */ private function is64BitSystem(): bool { - return PHP_INT_SIZE === 8 && !$this->disable64Bit; + return PHP_INT_SIZE === 8 && !$this->force32Bit; } } diff --git a/vendor/ramsey/uuid/src/Fields/SerializableFieldsTrait.php b/vendor/ramsey/uuid/src/Fields/SerializableFieldsTrait.php index 16e6525da..3d36b6f12 100644 --- a/vendor/ramsey/uuid/src/Fields/SerializableFieldsTrait.php +++ b/vendor/ramsey/uuid/src/Fields/SerializableFieldsTrait.php @@ -56,22 +56,23 @@ trait SerializableFieldsTrait /** * Constructs the object from a serialized string representation * - * @param string $serialized The serialized string representation of the object + * @param string $data The serialized string representation of the object * - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * @psalm-suppress UnusedMethodCall */ - public function unserialize($serialized): void + public function unserialize(string $data): void { - if (strlen($serialized) === 16) { - $this->__construct($serialized); + if (strlen($data) === 16) { + $this->__construct($data); } else { - $this->__construct(base64_decode($serialized)); + $this->__construct(base64_decode($data)); } } /** - * @param array{bytes: string} $data + * @param array{bytes?: string} $data + * + * @psalm-suppress UnusedMethodCall */ public function __unserialize(array $data): void { diff --git a/vendor/ramsey/uuid/src/Generator/CombGenerator.php b/vendor/ramsey/uuid/src/Generator/CombGenerator.php index 25b7988ec..0e8870608 100644 --- a/vendor/ramsey/uuid/src/Generator/CombGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/CombGenerator.php @@ -61,22 +61,10 @@ class CombGenerator implements RandomGeneratorInterface { public const TIMESTAMP_BYTES = 6; - /** - * @var RandomGeneratorInterface - */ - private $randomGenerator; - - /** - * @var NumberConverterInterface - */ - private $converter; - public function __construct( - RandomGeneratorInterface $generator, - NumberConverterInterface $numberConverter + private RandomGeneratorInterface $generator, + private NumberConverterInterface $numberConverter ) { - $this->converter = $numberConverter; - $this->randomGenerator = $generator; } /** @@ -95,11 +83,11 @@ class CombGenerator implements RandomGeneratorInterface $hash = ''; if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) { - $hash = $this->randomGenerator->generate($length - self::TIMESTAMP_BYTES); + $hash = $this->generator->generate($length - self::TIMESTAMP_BYTES); } $lsbTime = str_pad( - $this->converter->toHex($this->timestamp()), + $this->numberConverter->toHex($this->timestamp()), self::TIMESTAMP_BYTES * 2, '0', STR_PAD_LEFT diff --git a/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php b/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php index aca8c5db7..37ba78131 100644 --- a/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/DceSecurityGenerator.php @@ -52,29 +52,11 @@ class DceSecurityGenerator implements DceSecurityGeneratorInterface */ private const CLOCK_SEQ_LOW = 0; - /** - * @var NumberConverterInterface - */ - private $numberConverter; - - /** - * @var TimeGeneratorInterface - */ - private $timeGenerator; - - /** - * @var DceSecurityProviderInterface - */ - private $dceSecurityProvider; - public function __construct( - NumberConverterInterface $numberConverter, - TimeGeneratorInterface $timeGenerator, - DceSecurityProviderInterface $dceSecurityProvider + private NumberConverterInterface $numberConverter, + private TimeGeneratorInterface $timeGenerator, + private DceSecurityProviderInterface $dceSecurityProvider ) { - $this->numberConverter = $numberConverter; - $this->timeGenerator = $timeGenerator; - $this->dceSecurityProvider = $dceSecurityProvider; } public function generate( @@ -153,8 +135,7 @@ class DceSecurityGenerator implements DceSecurityGeneratorInterface // Replace bytes in the time-based UUID with DCE Security values. $bytes = substr_replace($bytes, $identifierBytes, 0, 4); - $bytes = substr_replace($bytes, $domainByte, 9, 1); - return $bytes; + return substr_replace($bytes, $domainByte, 9, 1); } } diff --git a/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php b/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php index d245c7bcc..a1b39b04a 100644 --- a/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php @@ -40,29 +40,11 @@ use const STR_PAD_LEFT; */ class DefaultTimeGenerator implements TimeGeneratorInterface { - /** - * @var NodeProviderInterface - */ - private $nodeProvider; - - /** - * @var TimeConverterInterface - */ - private $timeConverter; - - /** - * @var TimeProviderInterface - */ - private $timeProvider; - public function __construct( - NodeProviderInterface $nodeProvider, - TimeConverterInterface $timeConverter, - TimeProviderInterface $timeProvider + private NodeProviderInterface $nodeProvider, + private TimeConverterInterface $timeConverter, + private TimeProviderInterface $timeProvider ) { - $this->nodeProvider = $nodeProvider; - $this->timeConverter = $timeConverter; - $this->timeProvider = $timeProvider; } /** @@ -121,13 +103,13 @@ class DefaultTimeGenerator implements TimeGeneratorInterface * Uses the node provider given when constructing this instance to get * the node ID (usually a MAC address) * - * @param string|int|null $node A node value that may be used to override the node provider + * @param int|string|null $node A node value that may be used to override the node provider * * @return string 6-byte binary string representation of the node * * @throws InvalidArgumentException */ - private function getValidNode($node): string + private function getValidNode(int | string | null $node): string { if ($node === null) { $node = $this->nodeProvider->getNode(); diff --git a/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php b/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php index 3780c5c60..6a6d1aec3 100644 --- a/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php +++ b/vendor/ramsey/uuid/src/Generator/PeclUuidNameGenerator.php @@ -33,21 +33,16 @@ class PeclUuidNameGenerator implements NameGeneratorInterface /** @psalm-pure */ public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string { - switch ($hashAlgorithm) { - case 'md5': - $uuid = uuid_generate_md5($ns->toString(), $name); - - break; - case 'sha1': - $uuid = uuid_generate_sha1($ns->toString(), $name); - - break; - default: - throw new NameException(sprintf( + $uuid = match ($hashAlgorithm) { + 'md5' => uuid_generate_md5($ns->toString(), $name), + 'sha1' => uuid_generate_sha1($ns->toString(), $name), + default => throw new NameException( + sprintf( 'Unable to hash namespace and name with algorithm \'%s\'', $hashAlgorithm - )); - } + ) + ), + }; return uuid_parse($uuid); } diff --git a/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php b/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php index 5c83cb4d8..1180b9764 100644 --- a/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php +++ b/vendor/ramsey/uuid/src/Generator/RandomGeneratorInterface.php @@ -22,7 +22,7 @@ interface RandomGeneratorInterface /** * Generates a string of randomized binary data * - * @param int $length The number of bytes of random binary data to generate + * @param int<1, max> $length The number of bytes of random binary data to generate * * @return string A binary string */ diff --git a/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php b/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php index 793ccd5a4..fd0ccc8aa 100644 --- a/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php +++ b/vendor/ramsey/uuid/src/Generator/RandomLibAdapter.php @@ -29,10 +29,7 @@ use RandomLib\Generator; */ class RandomLibAdapter implements RandomGeneratorInterface { - /** - * @var Generator - */ - private $generator; + private Generator $generator; /** * Constructs a RandomLibAdapter diff --git a/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php b/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php index 3d55fc4d6..8d06fc3ae 100644 --- a/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php +++ b/vendor/ramsey/uuid/src/Generator/TimeGeneratorFactory.php @@ -24,29 +24,11 @@ use Ramsey\Uuid\Provider\TimeProviderInterface; */ class TimeGeneratorFactory { - /** - * @var NodeProviderInterface - */ - private $nodeProvider; - - /** - * @var TimeConverterInterface - */ - private $timeConverter; - - /** - * @var TimeProviderInterface - */ - private $timeProvider; - public function __construct( - NodeProviderInterface $nodeProvider, - TimeConverterInterface $timeConverter, - TimeProviderInterface $timeProvider + private NodeProviderInterface $nodeProvider, + private TimeConverterInterface $timeConverter, + private TimeProviderInterface $timeProvider ) { - $this->nodeProvider = $nodeProvider; - $this->timeConverter = $timeConverter; - $this->timeProvider = $timeProvider; } /** diff --git a/vendor/ramsey/uuid/src/Generator/UnixTimeGenerator.php b/vendor/ramsey/uuid/src/Generator/UnixTimeGenerator.php new file mode 100644 index 000000000..1aef8699a --- /dev/null +++ b/vendor/ramsey/uuid/src/Generator/UnixTimeGenerator.php @@ -0,0 +1,52 @@ +<?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\Generator; + +use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Provider\TimeProviderInterface; + +use function hex2bin; + +/** + * UnixTimeGenerator generates bytes that combine a 48-bit timestamp in + * milliseconds since the Unix Epoch with 80 random bits + */ +class UnixTimeGenerator implements TimeGeneratorInterface +{ + public function __construct( + private TimeConverterInterface $timeConverter, + private TimeProviderInterface $timeProvider, + private RandomGeneratorInterface $randomGenerator + ) { + } + + /** + * @inheritDoc + */ + public function generate($node = null, ?int $clockSeq = null): string + { + // Generate 10 random bytes to append to the string returned, since our + // time bytes will consist of 6 bytes. + $random = $this->randomGenerator->generate(10); + + $time = $this->timeProvider->getTime(); + $unixTimeHex = $this->timeConverter->calculateTime( + $time->getSeconds()->toString(), + $time->getMicroseconds()->toString(), + ); + + return hex2bin($unixTimeHex->toString()) . $random; + } +} diff --git a/vendor/ramsey/uuid/src/Guid/Fields.php b/vendor/ramsey/uuid/src/Guid/Fields.php index d8a1a2b10..0fc5d1c9b 100644 --- a/vendor/ramsey/uuid/src/Guid/Fields.php +++ b/vendor/ramsey/uuid/src/Guid/Fields.php @@ -17,6 +17,7 @@ namespace Ramsey\Uuid\Guid; use Ramsey\Uuid\Exception\InvalidArgumentException; use Ramsey\Uuid\Fields\SerializableFieldsTrait; use Ramsey\Uuid\Rfc4122\FieldsInterface; +use Ramsey\Uuid\Rfc4122\MaxTrait; use Ramsey\Uuid\Rfc4122\NilTrait; use Ramsey\Uuid\Rfc4122\VariantTrait; use Ramsey\Uuid\Rfc4122\VersionTrait; @@ -44,34 +45,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 a GUID * @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 ' @@ -149,7 +144,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)); } @@ -171,7 +172,7 @@ final class Fields implements FieldsInterface public function getVersion(): ?int { - if ($this->isNil()) { + if ($this->isNil() || $this->isMax()) { return null; } @@ -183,7 +184,7 @@ final class Fields implements FieldsInterface private function isCorrectVariant(): bool { - if ($this->isNil()) { + if ($this->isNil() || $this->isMax()) { return true; } diff --git a/vendor/ramsey/uuid/src/Guid/GuidBuilder.php b/vendor/ramsey/uuid/src/Guid/GuidBuilder.php index 758dd6b7f..c036bb20b 100644 --- a/vendor/ramsey/uuid/src/Guid/GuidBuilder.php +++ b/vendor/ramsey/uuid/src/Guid/GuidBuilder.php @@ -32,27 +32,15 @@ use Throwable; class GuidBuilder implements UuidBuilderInterface { /** - * @var NumberConverterInterface - */ - private $numberConverter; - - /** - * @var TimeConverterInterface - */ - private $timeConverter; - - /** * @param NumberConverterInterface $numberConverter The number converter to * use when constructing the Guid * @param TimeConverterInterface $timeConverter The time converter to use * for converting timestamps extracted from a UUID to Unix timestamps */ public function __construct( - NumberConverterInterface $numberConverter, - TimeConverterInterface $timeConverter + private NumberConverterInterface $numberConverter, + private TimeConverterInterface $timeConverter ) { - $this->numberConverter = $numberConverter; - $this->timeConverter = $timeConverter; } /** diff --git a/vendor/ramsey/uuid/src/Lazy/LazyUuidFromString.php b/vendor/ramsey/uuid/src/Lazy/LazyUuidFromString.php index 8ba757964..c0b47bbf2 100644 --- a/vendor/ramsey/uuid/src/Lazy/LazyUuidFromString.php +++ b/vendor/ramsey/uuid/src/Lazy/LazyUuidFromString.php @@ -18,8 +18,8 @@ use DateTimeInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; use Ramsey\Uuid\Exception\UnsupportedOperationException; use Ramsey\Uuid\Fields\FieldsInterface; -use Ramsey\Uuid\Nonstandard\UuidV6; use Ramsey\Uuid\Rfc4122\UuidV1; +use Ramsey\Uuid\Rfc4122\UuidV6; use Ramsey\Uuid\Type\Hexadecimal; use Ramsey\Uuid\Type\Integer as IntegerObject; use Ramsey\Uuid\UuidFactory; @@ -55,18 +55,14 @@ use function substr; final class LazyUuidFromString implements UuidInterface { public const VALID_REGEX = '/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/ms'; + + private ?UuidInterface $unwrapped = null; + /** - * @var string - * @psalm-var non-empty-string + * @psalm-param non-empty-string $uuid */ - private $uuid; - /** @var UuidInterface|null */ - private $unwrapped; - - /** @psalm-param non-empty-string $uuid */ - public function __construct(string $uuid) + public function __construct(private string $uuid) { - $this->uuid = $uuid; } /** @psalm-pure */ @@ -105,19 +101,20 @@ final class LazyUuidFromString implements UuidInterface /** * {@inheritDoc} * - * @param string $serialized + * @param string $data * - * @psalm-param non-empty-string $serialized + * @psalm-param non-empty-string $data */ - public function unserialize($serialized): void + public function unserialize(string $data): void { - $this->uuid = $serialized; + $this->uuid = $data; } /** - * @param array{string: string} $data + * @param array{string?: string} $data * - * @psalm-param array{string: non-empty-string} $data + * @psalm-param array{string?: non-empty-string} $data + * @psalm-suppress UnusedMethodCall */ public function __unserialize(array $data): void { diff --git a/vendor/ramsey/uuid/src/Nonstandard/Fields.php b/vendor/ramsey/uuid/src/Nonstandard/Fields.php index 927bc6a26..5dfe61076 100644 --- a/vendor/ramsey/uuid/src/Nonstandard/Fields.php +++ b/vendor/ramsey/uuid/src/Nonstandard/Fields.php @@ -48,25 +48,18 @@ final class Fields implements FieldsInterface use VariantTrait; /** - * @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 */ - 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; } public function getBytes(): string @@ -130,4 +123,9 @@ final class Fields implements FieldsInterface { return false; } + + public function isMax(): bool + { + return false; + } } diff --git a/vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php b/vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php index 0c8927738..82efd402f 100644 --- a/vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php +++ b/vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php @@ -30,27 +30,15 @@ use Throwable; class UuidBuilder implements UuidBuilderInterface { /** - * @var NumberConverterInterface - */ - private $numberConverter; - - /** - * @var TimeConverterInterface - */ - private $timeConverter; - - /** * @param NumberConverterInterface $numberConverter The number converter to * use when constructing the Nonstandard\Uuid * @param TimeConverterInterface $timeConverter The time converter to use * for converting timestamps extracted from a UUID to Unix timestamps */ public function __construct( - NumberConverterInterface $numberConverter, - TimeConverterInterface $timeConverter + private NumberConverterInterface $numberConverter, + private TimeConverterInterface $timeConverter ) { - $this->numberConverter = $numberConverter; - $this->timeConverter = $timeConverter; } /** diff --git a/vendor/ramsey/uuid/src/Nonstandard/UuidV6.php b/vendor/ramsey/uuid/src/Nonstandard/UuidV6.php index 05586b3eb..1a7bbaf75 100644 --- a/vendor/ramsey/uuid/src/Nonstandard/UuidV6.php +++ b/vendor/ramsey/uuid/src/Nonstandard/UuidV6.php @@ -14,39 +14,34 @@ declare(strict_types=1); namespace Ramsey\Uuid\Nonstandard; -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\Lazy\LazyUuidFromString; use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Rfc4122\TimeTrait; use Ramsey\Uuid\Rfc4122\UuidInterface; use Ramsey\Uuid\Rfc4122\UuidV1; use Ramsey\Uuid\Uuid; -use Throwable; - -use function hex2bin; -use function str_pad; -use function substr; - -use const STR_PAD_LEFT; /** - * Ordered-time, or version 6, UUIDs include timestamp, clock sequence, and node - * values that are combined into a 128-bit unsigned integer + * Reordered time, or version 6, UUIDs include timestamp, clock sequence, and + * node values that are combined into a 128-bit unsigned integer + * + * @deprecated Use {@see \Ramsey\Uuid\Rfc4122\UuidV6} instead. * * @link https://github.com/uuid6/uuid6-ietf-draft UUID version 6 IETF draft * @link http://gh.peabody.io/uuidv6/ "Version 6" UUIDs * * @psalm-immutable */ -final class UuidV6 extends Uuid implements UuidInterface +class UuidV6 extends Uuid implements UuidInterface { + use TimeTrait; + /** - * Creates a version 6 (time-based) UUID + * Creates a version 6 (reordered time) UUID * * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID * @param NumberConverterInterface $numberConverter The number converter to use @@ -62,10 +57,10 @@ final class UuidV6 extends Uuid implements UuidInterface CodecInterface $codec, TimeConverterInterface $timeConverter ) { - if ($fields->getVersion() !== Uuid::UUID_TYPE_PEABODY) { + if ($fields->getVersion() !== Uuid::UUID_TYPE_REORDERED_TIME) { throw new InvalidArgumentException( 'Fields used to create a UuidV6 must represent a ' - . 'version 6 (ordered-time) UUID' + . 'version 6 (reordered time) UUID' ); } @@ -73,29 +68,6 @@ final class UuidV6 extends Uuid implements UuidInterface } /** - * Returns a DateTimeInterface object representing the timestamp associated - * with the UUID - * - * @return DateTimeImmutable A PHP DateTimeImmutable instance representing - * the timestamp of a version 6 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); - } - } - - /** * Converts this UUID into an instance of a version 1 UUID */ public function toUuidV1(): UuidV1 @@ -116,7 +88,7 @@ final class UuidV6 extends Uuid implements UuidInterface /** * Converts a version 1 UUID into an instance of a version 6 UUID */ - public static function fromUuidV1(UuidV1 $uuidV1): UuidV6 + public static function fromUuidV1(UuidV1 $uuidV1): \Ramsey\Uuid\Rfc4122\UuidV6 { $hex = $uuidV1->getHex()->toString(); $hex = substr($hex, 13, 3) diff --git a/vendor/ramsey/uuid/src/Provider/Dce/SystemDceSecurityProvider.php b/vendor/ramsey/uuid/src/Provider/Dce/SystemDceSecurityProvider.php index 7ff407648..d5b6cf0c0 100644 --- a/vendor/ramsey/uuid/src/Provider/Dce/SystemDceSecurityProvider.php +++ b/vendor/ramsey/uuid/src/Provider/Dce/SystemDceSecurityProvider.php @@ -21,7 +21,6 @@ use Ramsey\Uuid\Type\Integer as IntegerObject; use function escapeshellarg; use function preg_split; use function str_getcsv; -use function strpos; use function strrpos; use function strtolower; use function strtoupper; @@ -42,6 +41,7 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface */ public function getUid(): IntegerObject { + /** @var int|float|string|IntegerObject|null $uid */ static $uid = null; if ($uid instanceof IntegerObject) { @@ -72,6 +72,7 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface */ public function getGid(): IntegerObject { + /** @var int|float|string|IntegerObject|null $gid */ static $gid = null; if ($gid instanceof IntegerObject) { @@ -104,15 +105,10 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface return ''; } - switch ($this->getOs()) { - case 'WIN': - return $this->getWindowsUid(); - case 'DAR': - case 'FRE': - case 'LIN': - default: - return trim((string) shell_exec('id -u')); - } + return match ($this->getOs()) { + 'WIN' => $this->getWindowsUid(), + default => trim((string) shell_exec('id -u')), + }; } /** @@ -124,15 +120,10 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface return ''; } - switch ($this->getOs()) { - case 'WIN': - return $this->getWindowsGid(); - case 'DAR': - case 'FRE': - case 'LIN': - default: - return trim((string) shell_exec('id -g')); - } + return match ($this->getOs()) { + 'WIN' => $this->getWindowsGid(), + default => trim((string) shell_exec('id -g')), + }; } /** @@ -142,7 +133,7 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface { $disabledFunctions = strtolower((string) ini_get('disable_functions')); - return strpos($disabledFunctions, 'shell_exec') === false; + return !str_contains($disabledFunctions, 'shell_exec'); } /** @@ -150,7 +141,13 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface */ private function getOs(): string { - return strtoupper(substr(constant('PHP_OS'), 0, 3)); + /** + * @psalm-suppress UnnecessaryVarAnnotation + * @var string $phpOs + */ + $phpOs = constant('PHP_OS'); + + return strtoupper(substr($phpOs, 0, 3)); } /** diff --git a/vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php b/vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php index fe890cc4d..d2eb20b70 100644 --- a/vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php +++ b/vendor/ramsey/uuid/src/Provider/Node/FallbackNodeProvider.php @@ -25,23 +25,17 @@ use Ramsey\Uuid\Type\Hexadecimal; class FallbackNodeProvider implements NodeProviderInterface { /** - * @var iterable<NodeProviderInterface> - */ - private $nodeProviders; - - /** * @param iterable<NodeProviderInterface> $providers Array of node providers */ - public function __construct(iterable $providers) + public function __construct(private iterable $providers) { - $this->nodeProviders = $providers; } public function getNode(): Hexadecimal { $lastProviderException = null; - foreach ($this->nodeProviders as $provider) { + foreach ($this->providers as $provider) { try { return $provider->getNode(); } catch (NodeException $exception) { diff --git a/vendor/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php b/vendor/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php index 51f1b02ea..0f7536a82 100644 --- a/vendor/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php +++ b/vendor/ramsey/uuid/src/Provider/Node/StaticNodeProvider.php @@ -32,10 +32,7 @@ use const STR_PAD_LEFT; */ class StaticNodeProvider implements NodeProviderInterface { - /** - * @var Hexadecimal - */ - private $node; + private Hexadecimal $node; /** * @param Hexadecimal $node The static node value to use diff --git a/vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php b/vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php index d512f22aa..d0a1e697f 100644 --- a/vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php +++ b/vendor/ramsey/uuid/src/Provider/Node/SystemNodeProvider.php @@ -27,8 +27,8 @@ use function ob_start; use function preg_match; use function preg_match_all; use function reset; +use function str_contains; use function str_replace; -use function strpos; use function strtolower; use function strtoupper; use function substr; @@ -100,12 +100,18 @@ class SystemNodeProvider implements NodeProviderInterface { $disabledFunctions = strtolower((string) ini_get('disable_functions')); - if (strpos($disabledFunctions, 'passthru') !== false) { + if (str_contains($disabledFunctions, 'passthru')) { return ''; } + /** + * @psalm-suppress UnnecessaryVarAnnotation + * @var string $phpOs + */ + $phpOs = constant('PHP_OS'); + ob_start(); - switch (strtoupper(substr(constant('PHP_OS'), 0, 3))) { + switch (strtoupper(substr($phpOs, 0, 3))) { case 'WIN': passthru('ipconfig /all 2>&1'); @@ -142,13 +148,20 @@ class SystemNodeProvider implements NodeProviderInterface { $mac = ''; - if (strtoupper(constant('PHP_OS')) === 'LINUX') { + /** + * @psalm-suppress UnnecessaryVarAnnotation + * @var string $phpOs + */ + $phpOs = constant('PHP_OS'); + + if (strtoupper($phpOs) === 'LINUX') { $addressPaths = glob('/sys/class/net/*/address', GLOB_NOSORT); if ($addressPaths === false || count($addressPaths) === 0) { return ''; } + /** @var array<array-key, string> $macs */ $macs = []; array_walk($addressPaths, function (string $addressPath) use (&$macs): void { @@ -157,7 +170,10 @@ class SystemNodeProvider implements NodeProviderInterface } }); - $macs = array_map('trim', $macs); + /** @var callable $trim */ + $trim = 'trim'; + + $macs = array_map($trim, $macs); // Remove invalid entries. $macs = array_filter($macs, function (string $address) { @@ -165,6 +181,7 @@ class SystemNodeProvider implements NodeProviderInterface && preg_match(self::SYSFS_PATTERN, $address); }); + /** @var string|bool $mac */ $mac = reset($macs); } diff --git a/vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php b/vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php index b8bfd7215..526c8ff46 100644 --- a/vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php +++ b/vendor/ramsey/uuid/src/Provider/Time/FixedTimeProvider.php @@ -19,21 +19,15 @@ use Ramsey\Uuid\Type\Integer as IntegerObject; use Ramsey\Uuid\Type\Time; /** - * FixedTimeProvider uses an known time to provide the time + * FixedTimeProvider uses a known time to provide the time * * This provider allows the use of a previously-generated, or known, time * when generating time-based UUIDs. */ class FixedTimeProvider implements TimeProviderInterface { - /** - * @var Time - */ - private $fixedTime; - - public function __construct(Time $time) + public function __construct(private Time $time) { - $this->fixedTime = $time; } /** @@ -43,7 +37,7 @@ class FixedTimeProvider implements TimeProviderInterface */ public function setUsec($value): void { - $this->fixedTime = new Time($this->fixedTime->getSeconds(), $value); + $this->time = new Time($this->time->getSeconds(), $value); } /** @@ -53,11 +47,11 @@ class FixedTimeProvider implements TimeProviderInterface */ public function setSec($value): void { - $this->fixedTime = new Time($value, $this->fixedTime->getMicroseconds()); + $this->time = new Time($value, $this->time->getMicroseconds()); } public function getTime(): Time { - return $this->fixedTime; + return $this->time; } } 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, + }; } } diff --git a/vendor/ramsey/uuid/src/Type/Decimal.php b/vendor/ramsey/uuid/src/Type/Decimal.php index 10f93845b..acc5e754b 100644 --- a/vendor/ramsey/uuid/src/Type/Decimal.php +++ b/vendor/ramsey/uuid/src/Type/Decimal.php @@ -19,6 +19,7 @@ use ValueError; use function is_numeric; use function sprintf; +use function str_starts_with; /** * A value object representing a decimal @@ -34,20 +35,10 @@ use function sprintf; */ final class Decimal implements NumberInterface { - /** - * @var string - */ - private $value; - - /** - * @var bool - */ - private $isNegative = false; + private string $value; + private bool $isNegative = false; - /** - * @param mixed $value The decimal value to store - */ - public function __construct($value) + public function __construct(float | int | string | self $value) { $value = (string) $value; @@ -59,7 +50,7 @@ final class Decimal implements NumberInterface } // Remove the leading +-symbol. - if (strpos($value, '+') === 0) { + if (str_starts_with($value, '+')) { $value = substr($value, 1); } @@ -68,7 +59,7 @@ final class Decimal implements NumberInterface $value = '0'; } - if (strpos($value, '-') === 0) { + if (str_starts_with($value, '-')) { $this->isNegative = true; } @@ -111,18 +102,19 @@ final class Decimal implements NumberInterface /** * Constructs the object from a serialized string representation * - * @param string $serialized The serialized string representation of the object + * @param string $data The serialized string representation of the object * - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * @psalm-suppress UnusedMethodCall */ - public function unserialize($serialized): void + public function unserialize(string $data): void { - $this->__construct($serialized); + $this->__construct($data); } /** - * @param array{string: string} $data + * @param array{string?: string} $data + * + * @psalm-suppress UnusedMethodCall */ public function __unserialize(array $data): void { diff --git a/vendor/ramsey/uuid/src/Type/Hexadecimal.php b/vendor/ramsey/uuid/src/Type/Hexadecimal.php index 88adc2e7e..3c8f30adf 100644 --- a/vendor/ramsey/uuid/src/Type/Hexadecimal.php +++ b/vendor/ramsey/uuid/src/Type/Hexadecimal.php @@ -19,7 +19,7 @@ use ValueError; use function ctype_xdigit; use function sprintf; -use function strpos; +use function str_starts_with; use function strtolower; use function substr; @@ -34,10 +34,7 @@ use function substr; */ final class Hexadecimal implements TypeInterface { - /** - * @var string - */ - private $value; + private string $value; /** * @param string $value The hexadecimal value to store @@ -46,7 +43,7 @@ final class Hexadecimal implements TypeInterface { $value = strtolower($value); - if (strpos($value, '0x') === 0) { + if (str_starts_with($value, '0x')) { $value = substr($value, 2); } @@ -90,18 +87,17 @@ final class Hexadecimal implements TypeInterface /** * Constructs the object from a serialized string representation * - * @param string $serialized The serialized string representation of the object + * @param string $data The serialized string representation of the object * - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * @psalm-suppress UnusedMethodCall */ - public function unserialize($serialized): void + public function unserialize(string $data): void { - $this->__construct($serialized); + $this->__construct($data); } /** - * @param array{string: string} $data + * @param array{string?: string} $data */ public function __unserialize(array $data): void { diff --git a/vendor/ramsey/uuid/src/Type/Integer.php b/vendor/ramsey/uuid/src/Type/Integer.php index 7690f6cd8..e41b3cad5 100644 --- a/vendor/ramsey/uuid/src/Type/Integer.php +++ b/vendor/ramsey/uuid/src/Type/Integer.php @@ -20,7 +20,7 @@ use ValueError; use function ctype_digit; use function ltrim; use function sprintf; -use function strpos; +use function str_starts_with; use function substr; /** @@ -40,23 +40,17 @@ final class Integer implements NumberInterface /** * @psalm-var numeric-string */ - private $value; + private string $value; - /** - * @var bool - */ - private $isNegative = false; + private bool $isNegative = false; - /** - * @param mixed $value The integer value to store - */ - public function __construct($value) + public function __construct(float | int | string | self $value) { $value = (string) $value; $sign = '+'; // If the value contains a sign, remove it for ctype_digit() check. - if (strpos($value, '-') === 0 || strpos($value, '+') === 0) { + if (str_starts_with($value, '-') || str_starts_with($value, '+')) { $sign = substr($value, 0, 1); $value = substr($value, 1); } @@ -127,18 +121,17 @@ final class Integer implements NumberInterface /** * Constructs the object from a serialized string representation * - * @param string $serialized The serialized string representation of the object + * @param string $data The serialized string representation of the object * - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * @psalm-suppress UnusedMethodCall */ - public function unserialize($serialized): void + public function unserialize(string $data): void { - $this->__construct($serialized); + $this->__construct($data); } /** - * @param array{string: string} $data + * @param array{string?: string} $data */ public function __unserialize(array $data): void { diff --git a/vendor/ramsey/uuid/src/Type/Time.php b/vendor/ramsey/uuid/src/Type/Time.php index dd1b8bc28..745b5ccab 100644 --- a/vendor/ramsey/uuid/src/Type/Time.php +++ b/vendor/ramsey/uuid/src/Type/Time.php @@ -17,7 +17,6 @@ namespace Ramsey\Uuid\Type; use Ramsey\Uuid\Exception\UnsupportedOperationException; use Ramsey\Uuid\Type\Integer as IntegerObject; use ValueError; -use stdClass; use function json_decode; use function json_encode; @@ -34,22 +33,13 @@ use function sprintf; */ final class Time implements TypeInterface { - /** - * @var IntegerObject - */ - private $seconds; - - /** - * @var IntegerObject - */ - private $microseconds; + private IntegerObject $seconds; + private IntegerObject $microseconds; - /** - * @param mixed $seconds - * @param mixed $microseconds - */ - public function __construct($seconds, $microseconds = 0) - { + public function __construct( + float | int | string | IntegerObject $seconds, + float | int | string | IntegerObject $microseconds = 0, + ) { $this->seconds = new IntegerObject($seconds); $this->microseconds = new IntegerObject($microseconds); } @@ -104,27 +94,26 @@ final class Time implements TypeInterface /** * Constructs the object from a serialized string representation * - * @param string $serialized The serialized string representation of the object + * @param string $data The serialized string representation of the object * - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * @psalm-suppress UnusedMethodCall */ - public function unserialize($serialized): void + public function unserialize(string $data): void { - /** @var stdClass $time */ - $time = json_decode($serialized); + /** @var array{seconds?: int|float|string, microseconds?: int|float|string} $time */ + $time = json_decode($data, true); - if (!isset($time->seconds) || !isset($time->microseconds)) { + if (!isset($time['seconds']) || !isset($time['microseconds'])) { throw new UnsupportedOperationException( 'Attempted to unserialize an invalid value' ); } - $this->__construct($time->seconds, $time->microseconds); + $this->__construct($time['seconds'], $time['microseconds']); } /** - * @param array{seconds: string, microseconds: string} $data + * @param array{seconds?: string, microseconds?: string} $data */ public function __unserialize(array $data): void { diff --git a/vendor/ramsey/uuid/src/Uuid.php b/vendor/ramsey/uuid/src/Uuid.php index 5f0922b9c..6656aba02 100644 --- a/vendor/ramsey/uuid/src/Uuid.php +++ b/vendor/ramsey/uuid/src/Uuid.php @@ -18,6 +18,7 @@ use DateTimeInterface; use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\UnsupportedOperationException; use Ramsey\Uuid\Fields\FieldsInterface; use Ramsey\Uuid\Lazy\LazyUuidFromString; use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; @@ -27,6 +28,7 @@ use ValueError; use function assert; use function bin2hex; +use function method_exists; use function preg_match; use function sprintf; use function str_replace; @@ -83,6 +85,14 @@ class Uuid implements UuidInterface public const NIL = '00000000-0000-0000-0000-000000000000'; /** + * 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 + */ + public const MAX = 'ffffffff-ffff-ffff-ffff-ffffffffffff'; + + /** * Variant: reserved, NCS backward compatibility * * @link http://tools.ietf.org/html/rfc4122#section-4.1.1 RFC 4122, § 4.1.1: Variant @@ -116,7 +126,7 @@ class Uuid implements UuidInterface public const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$'; /** - * Version 1 (time-based) UUID + * Version 1 (Gregorian time) UUID * * @link https://tools.ietf.org/html/rfc4122#section-4.1.3 RFC 4122, § 4.1.3: Version */ @@ -156,15 +166,23 @@ class Uuid implements UuidInterface public const UUID_TYPE_HASH_SHA1 = 5; /** - * Version 6 (ordered-time) UUID + * @deprecated Use {@see Uuid::UUID_TYPE_REORDERED_TIME} instead. + */ + public const UUID_TYPE_PEABODY = 6; + + /** + * Version 6 (reordered time) UUID * - * This is named `UUID_TYPE_PEABODY`, since the specification is still in - * draft form, and the primary author/editor's name is Brad Peabody. + * @link https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.1 UUID Version 6 + */ + public const UUID_TYPE_REORDERED_TIME = 6; + + /** + * Version 7 (Unix Epoch time) UUID * - * @link https://github.com/uuid6/uuid6-ietf-draft UUID version 6 IETF draft - * @link http://gh.peabody.io/uuidv6/ "Version 6" UUIDs + * @link https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.2 UUID Version 7 */ - public const UUID_TYPE_PEABODY = 6; + public const UUID_TYPE_UNIX_TIME = 7; /** * DCE Security principal domain @@ -198,38 +216,19 @@ class Uuid implements UuidInterface self::DCE_DOMAIN_ORG => 'org', ]; - /** - * @var UuidFactoryInterface|null - */ - private static $factory = null; - - /** - * @var bool flag to detect if the UUID factory was replaced internally, which disables all optimizations - * for the default/happy path internal scenarios - */ - private static $factoryReplaced = false; - - /** - * @var CodecInterface - */ - protected $codec; - - /** - * The fields that make up this UUID - * - * @var Rfc4122FieldsInterface - */ - protected $fields; + private static ?UuidFactoryInterface $factory = null; /** - * @var NumberConverterInterface + * @var bool flag to detect if the UUID factory was replaced internally, + * which disables all optimizations for the default/happy path internal + * scenarios */ - protected $numberConverter; + private static bool $factoryReplaced = false; - /** - * @var TimeConverterInterface - */ - protected $timeConverter; + protected CodecInterface $codec; + protected NumberConverterInterface $numberConverter; + protected Rfc4122FieldsInterface $fields; + protected TimeConverterInterface $timeConverter; /** * Creates a universally unique identifier (UUID) from an array of fields @@ -302,19 +301,17 @@ class Uuid implements UuidInterface /** * Re-constructs the object from its serialized form * - * @param string $serialized The serialized PHP string to unserialize into + * @param string $data The serialized PHP string to unserialize into * a UuidInterface instance - * - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ - public function unserialize($serialized): void + public function unserialize(string $data): void { - if (strlen($serialized) === 16) { + if (strlen($data) === 16) { /** @var Uuid $uuid */ - $uuid = self::getFactory()->fromBytes($serialized); + $uuid = self::getFactory()->fromBytes($data); } else { /** @var Uuid $uuid */ - $uuid = self::getFactory()->fromString($serialized); + $uuid = self::getFactory()->fromString($data); } $this->codec = $uuid->codec; @@ -324,7 +321,7 @@ class Uuid implements UuidInterface } /** - * @param array{bytes: string} $data + * @param array{bytes?: string} $data */ public function __unserialize(array $data): void { @@ -384,6 +381,11 @@ class Uuid implements UuidInterface return new IntegerObject($this->numberConverter->fromHex($this->getHex()->toString())); } + public function getUrn(): string + { + return 'urn:uuid:' . $this->toString(); + } + /** * @psalm-return non-empty-string */ @@ -532,6 +534,8 @@ 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 */ public static function isValid(string $uuid): bool { @@ -539,7 +543,7 @@ class Uuid implements UuidInterface } /** - * Returns a version 1 (time-based) UUID from a host ID, sequence number, + * Returns a version 1 (Gregorian time) UUID from a host ID, sequence number, * and the current time * * @param Hexadecimal|int|string|null $node A 48-bit number representing the @@ -644,7 +648,7 @@ class Uuid implements UuidInterface } /** - * Returns a version 6 (ordered-time) UUID from a host ID, sequence number, + * Returns a version 6 (reordered time) UUID from a host ID, sequence number, * and the current time * * @param Hexadecimal|null $node A 48-bit number representing the hardware @@ -662,4 +666,28 @@ class Uuid implements UuidInterface ): UuidInterface { return self::getFactory()->uuid6($node, $clockSeq); } + + /** + * Returns a version 7 (Unix Epoch time) UUID + * + * @param DateTimeInterface|null $dateTime An optional date/time from which + * to create the version 7 UUID. If not provided, the UUID is generated + * using the current date/time. + * + * @return UuidInterface A UuidInterface instance that represents a + * version 7 UUID + */ + public static function uuid7(?DateTimeInterface $dateTime = null): UuidInterface + { + $factory = self::getFactory(); + + if (method_exists($factory, 'uuid7')) { + /** @var UuidInterface */ + return $factory->uuid7($dateTime); + } + + throw new UnsupportedOperationException( + 'The provided factory does not support the uuid7() method', + ); + } } diff --git a/vendor/ramsey/uuid/src/UuidFactory.php b/vendor/ramsey/uuid/src/UuidFactory.php index 6f2cea061..ab730f741 100644 --- a/vendor/ramsey/uuid/src/UuidFactory.php +++ b/vendor/ramsey/uuid/src/UuidFactory.php @@ -18,13 +18,16 @@ use DateTimeInterface; 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\Generator\DceSecurityGeneratorInterface; use Ramsey\Uuid\Generator\DefaultTimeGenerator; use Ramsey\Uuid\Generator\NameGeneratorInterface; use Ramsey\Uuid\Generator\RandomGeneratorInterface; use Ramsey\Uuid\Generator\TimeGeneratorInterface; +use Ramsey\Uuid\Generator\UnixTimeGenerator; use Ramsey\Uuid\Lazy\LazyUuidFromString; +use Ramsey\Uuid\Math\BrickMathCalculator; use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Provider\Time\FixedTimeProvider; use Ramsey\Uuid\Type\Hexadecimal; @@ -45,61 +48,26 @@ use const STR_PAD_LEFT; class UuidFactory implements UuidFactoryInterface { - /** - * @var CodecInterface - */ - private $codec; - - /** - * @var DceSecurityGeneratorInterface - */ - private $dceSecurityGenerator; - - /** - * @var NameGeneratorInterface - */ - private $nameGenerator; - - /** - * @var NodeProviderInterface - */ - private $nodeProvider; - - /** - * @var NumberConverterInterface - */ - private $numberConverter; - - /** - * @var RandomGeneratorInterface - */ - private $randomGenerator; - - /** - * @var TimeConverterInterface - */ - private $timeConverter; - - /** - * @var TimeGeneratorInterface - */ - private $timeGenerator; - - /** - * @var UuidBuilderInterface - */ - private $uuidBuilder; + private CodecInterface $codec; + private DceSecurityGeneratorInterface $dceSecurityGenerator; + private NameGeneratorInterface $nameGenerator; + private NodeProviderInterface $nodeProvider; + private NumberConverterInterface $numberConverter; + private RandomGeneratorInterface $randomGenerator; + private TimeConverterInterface $timeConverter; + private TimeGeneratorInterface $timeGenerator; + private TimeGeneratorInterface $unixTimeGenerator; + private UuidBuilderInterface $uuidBuilder; + private ValidatorInterface $validator; /** - * @var ValidatorInterface + * @var bool whether the feature set was provided from outside, or we can + * operate under "default" assumptions */ - private $validator; - - /** @var bool whether the feature set was provided from outside, or we can operate under "default" assumptions */ - private $isDefaultFeatureSet; + private bool $isDefaultFeatureSet; /** - * @param FeatureSet $features A set of available features in the current environment + * @param FeatureSet|null $features A set of available features in the current environment */ public function __construct(?FeatureSet $features = null) { @@ -117,6 +85,7 @@ class UuidFactory implements UuidFactoryInterface $this->timeGenerator = $features->getTimeGenerator(); $this->uuidBuilder = $features->getBuilder(); $this->validator = $features->getValidator(); + $this->unixTimeGenerator = $features->getUnixTimeGenerator(); } /** @@ -342,7 +311,7 @@ class UuidFactory implements UuidFactoryInterface $bytes = $timeGenerator->generate($nodeHex, $clockSeq); - return $this->uuidFromBytesAndVersion($bytes, 1); + return $this->uuidFromBytesAndVersion($bytes, Uuid::UUID_TYPE_TIME); } /** @@ -352,7 +321,7 @@ class UuidFactory implements UuidFactoryInterface { $bytes = $this->timeGenerator->generate($node, $clockSeq); - return $this->uuidFromBytesAndVersion($bytes, 1); + return $this->uuidFromBytesAndVersion($bytes, Uuid::UUID_TYPE_TIME); } public function uuid2( @@ -368,7 +337,7 @@ class UuidFactory implements UuidFactoryInterface $clockSeq ); - return $this->uuidFromBytesAndVersion($bytes, 2); + return $this->uuidFromBytesAndVersion($bytes, Uuid::UUID_TYPE_DCE_SECURITY); } /** @@ -377,14 +346,14 @@ class UuidFactory implements UuidFactoryInterface */ public function uuid3($ns, string $name): UuidInterface { - return $this->uuidFromNsAndName($ns, $name, 3, 'md5'); + return $this->uuidFromNsAndName($ns, $name, Uuid::UUID_TYPE_HASH_MD5, 'md5'); } public function uuid4(): UuidInterface { $bytes = $this->randomGenerator->generate(16); - return $this->uuidFromBytesAndVersion($bytes, 4); + return $this->uuidFromBytesAndVersion($bytes, Uuid::UUID_TYPE_RANDOM); } /** @@ -393,7 +362,7 @@ class UuidFactory implements UuidFactoryInterface */ public function uuid5($ns, string $name): UuidInterface { - return $this->uuidFromNsAndName($ns, $name, 5, 'sha1'); + return $this->uuidFromNsAndName($ns, $name, Uuid::UUID_TYPE_HASH_SHA1, 'sha1'); } public function uuid6(?Hexadecimal $node = null, ?int $clockSeq = null): UuidInterface @@ -412,7 +381,38 @@ class UuidFactory implements UuidFactoryInterface $v6Bytes = hex2bin(substr($v6, 1, 12) . '0' . substr($v6, -3)); $v6Bytes .= substr($bytes, 8); - return $this->uuidFromBytesAndVersion($v6Bytes, 6); + return $this->uuidFromBytesAndVersion($v6Bytes, Uuid::UUID_TYPE_REORDERED_TIME); + } + + /** + * Returns a version 7 (Unix Epoch time) UUID + * + * @param DateTimeInterface|null $dateTime An optional date/time from which + * to create the version 7 UUID. If not provided, the UUID is generated + * using the current date/time. + * + * @return UuidInterface A UuidInterface instance that represents a + * version 7 UUID + */ + public function uuid7(?DateTimeInterface $dateTime = null): UuidInterface + { + if ($dateTime !== null) { + $timeProvider = new FixedTimeProvider( + new Time($dateTime->format('U'), $dateTime->format('u')) + ); + + $timeGenerator = new UnixTimeGenerator( + new UnixTimeConverter(new BrickMathCalculator()), + $timeProvider, + $this->randomGenerator, + ); + + $bytes = $timeGenerator->generate(); + } else { + $bytes = $this->unixTimeGenerator->generate(); + } + + return $this->uuidFromBytesAndVersion($bytes, Uuid::UUID_TYPE_UNIX_TIME); } /** @@ -447,8 +447,12 @@ class UuidFactory implements UuidFactoryInterface * * @psalm-pure */ - private function uuidFromNsAndName($ns, string $name, int $version, string $hashAlgorithm): UuidInterface - { + private function uuidFromNsAndName( + UuidInterface | string $ns, + string $name, + int $version, + string $hashAlgorithm + ): UuidInterface { if (!($ns instanceof UuidInterface)) { $ns = $this->fromString($ns); } diff --git a/vendor/ramsey/uuid/src/UuidFactoryInterface.php b/vendor/ramsey/uuid/src/UuidFactoryInterface.php index 468cc6377..d99fc9d58 100644 --- a/vendor/ramsey/uuid/src/UuidFactoryInterface.php +++ b/vendor/ramsey/uuid/src/UuidFactoryInterface.php @@ -26,6 +26,61 @@ use Ramsey\Uuid\Validator\ValidatorInterface; interface UuidFactoryInterface { /** + * Creates a UUID from a byte string + * + * @param string $bytes A binary string + * + * @return UuidInterface A UuidInterface instance created from a binary + * string representation + * + * @psalm-pure + */ + public function fromBytes(string $bytes): UuidInterface; + + /** + * Creates a UUID from a DateTimeInterface instance + * + * @param DateTimeInterface $dateTime The date and time + * @param Hexadecimal|null $node A 48-bit number representing the hardware + * address + * @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 + * + * @return UuidInterface A UuidInterface instance that represents a + * version 1 UUID created from a DateTimeInterface instance + */ + public function fromDateTime( + DateTimeInterface $dateTime, + ?Hexadecimal $node = null, + ?int $clockSeq = null + ): UuidInterface; + + /** + * Creates a UUID from a 128-bit integer string + * + * @param string $integer String representation of 128-bit integer + * + * @return UuidInterface A UuidInterface instance created from the string + * representation of a 128-bit integer + * + * @psalm-pure + */ + public function fromInteger(string $integer): UuidInterface; + + /** + * Creates a UUID from the string standard representation + * + * @param string $uuid A hexadecimal string + * + * @return UuidInterface A UuidInterface instance created from a hexadecimal + * string representation + * + * @psalm-pure + */ + public function fromString(string $uuid): UuidInterface; + + /** * Returns the validator to use for the factory * * @psalm-mutation-free @@ -33,7 +88,7 @@ interface UuidFactoryInterface public function getValidator(): ValidatorInterface; /** - * Returns a version 1 (time-based) UUID from a host ID, sequence number, + * Returns a version 1 (Gregorian time) UUID from a host ID, sequence number, * and the current time * * @param Hexadecimal|int|string|null $node A 48-bit number representing the @@ -111,7 +166,7 @@ interface UuidFactoryInterface public function uuid5($ns, string $name): UuidInterface; /** - * Returns a version 6 (ordered-time) UUID from a host ID, sequence number, + * Returns a version 6 (reordered time) UUID from a host ID, sequence number, * and the current time * * @param Hexadecimal|null $node A 48-bit number representing the hardware @@ -124,59 +179,4 @@ interface UuidFactoryInterface * version 6 UUID */ public function uuid6(?Hexadecimal $node = null, ?int $clockSeq = null): UuidInterface; - - /** - * Creates a UUID from a byte string - * - * @param string $bytes A binary string - * - * @return UuidInterface A UuidInterface instance created from a binary - * string representation - * - * @psalm-pure - */ - public function fromBytes(string $bytes): UuidInterface; - - /** - * Creates a UUID from the string standard representation - * - * @param string $uuid A hexadecimal string - * - * @return UuidInterface A UuidInterface instance created from a hexadecimal - * string representation - * - * @psalm-pure - */ - public function fromString(string $uuid): UuidInterface; - - /** - * Creates a UUID from a 128-bit integer string - * - * @param string $integer String representation of 128-bit integer - * - * @return UuidInterface A UuidInterface instance created from the string - * representation of a 128-bit integer - * - * @psalm-pure - */ - public function fromInteger(string $integer): UuidInterface; - - /** - * Creates a UUID from a DateTimeInterface instance - * - * @param DateTimeInterface $dateTime The date and time - * @param Hexadecimal|null $node A 48-bit number representing the hardware - * address - * @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 - * - * @return UuidInterface A UuidInterface instance that represents a - * version 1 UUID created from a DateTimeInterface instance - */ - public function fromDateTime( - DateTimeInterface $dateTime, - ?Hexadecimal $node = null, - ?int $clockSeq = null - ): UuidInterface; } diff --git a/vendor/ramsey/uuid/src/UuidInterface.php b/vendor/ramsey/uuid/src/UuidInterface.php index f22eb0f99..5f41675bf 100644 --- a/vendor/ramsey/uuid/src/UuidInterface.php +++ b/vendor/ramsey/uuid/src/UuidInterface.php @@ -84,6 +84,14 @@ interface UuidInterface extends public function getInteger(): IntegerObject; /** + * 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; + + /** * Returns the string standard representation of the UUID * * @psalm-return non-empty-string diff --git a/vendor/ramsey/uuid/src/functions.php b/vendor/ramsey/uuid/src/functions.php index f5df1488d..fa80f4e85 100644 --- a/vendor/ramsey/uuid/src/functions.php +++ b/vendor/ramsey/uuid/src/functions.php @@ -15,17 +15,18 @@ declare(strict_types=1); namespace Ramsey\Uuid; +use DateTimeInterface; use Ramsey\Uuid\Type\Hexadecimal; use Ramsey\Uuid\Type\Integer as IntegerObject; /** - * Returns a version 1 (time-based) UUID from a host ID, sequence number, + * Returns a version 1 (Gregorian time) UUID from a host ID, sequence number, * and the current time * * @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 * @@ -106,12 +107,12 @@ function v5($ns, string $name): string } /** - * Returns a version 6 (ordered-time) UUID from a host ID, sequence number, + * Returns a version 6 (reordered time) UUID from a host ID, sequence number, * and the current time * * @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 * @@ -121,3 +122,17 @@ function v6(?Hexadecimal $node = null, ?int $clockSeq = null): string { return Uuid::uuid6($node, $clockSeq)->toString(); } + +/** + * Returns a version 7 (Unix Epoch time) UUID + * + * @param DateTimeInterface|null $dateTime An optional date/time from which + * to create the version 7 UUID. If not provided, the UUID is generated + * using the current date/time. + * + * @return non-empty-string Version 7 UUID as a string + */ +function v7(?DateTimeInterface $dateTime = null): string +{ + return Uuid::uuid7($dateTime)->toString(); +} |