diff --git a/LICENSE b/LICENSE index 9c2c7f1..11caf64 100644 --- a/LICENSE +++ b/LICENSE @@ -53,3 +53,26 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------ +Symfony - uid + +Copyright (c) 2020-2022 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/ncc/ThirdParty/Symfony/uid/AbstractUid.php b/src/ncc/ThirdParty/Symfony/uid/AbstractUid.php new file mode 100644 index 0000000..8bbe31b --- /dev/null +++ b/src/ncc/ThirdParty/Symfony/uid/AbstractUid.php @@ -0,0 +1,156 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ncc\Symfony\Component\Uid; + +/** + * @author Nicolas Grekas
+ */ +abstract class AbstractUid implements \JsonSerializable +{ + /** + * The identifier in its canonic representation. + */ + protected $uid; + + /** + * Whether the passed value is valid for the constructor of the current class. + */ + abstract public static function isValid(string $uid): bool; + + /** + * Creates an AbstractUid from an identifier represented in any of the supported formats. + * + * @throws \InvalidArgumentException When the passed value is not valid + */ + abstract public static function fromString(string $uid): static; + + /** + * @throws \InvalidArgumentException When the passed value is not valid + */ + public static function fromBinary(string $uid): static + { + if (16 !== \strlen($uid)) { + throw new \InvalidArgumentException('Invalid binary uid provided.'); + } + + return static::fromString($uid); + } + + /** + * @throws \InvalidArgumentException When the passed value is not valid + */ + public static function fromBase58(string $uid): static + { + if (22 !== \strlen($uid)) { + throw new \InvalidArgumentException('Invalid base-58 uid provided.'); + } + + return static::fromString($uid); + } + + /** + * @throws \InvalidArgumentException When the passed value is not valid + */ + public static function fromBase32(string $uid): static + { + if (26 !== \strlen($uid)) { + throw new \InvalidArgumentException('Invalid base-32 uid provided.'); + } + + return static::fromString($uid); + } + + /** + * @throws \InvalidArgumentException When the passed value is not valid + */ + public static function fromRfc4122(string $uid): static + { + if (36 !== \strlen($uid)) { + throw new \InvalidArgumentException('Invalid RFC4122 uid provided.'); + } + + return static::fromString($uid); + } + + /** + * Returns the identifier as a raw binary string. + */ + abstract public function toBinary(): string; + + /** + * Returns the identifier as a base58 case sensitive string. + */ + public function toBase58(): string + { + return strtr(sprintf('%022s', BinaryUtil::toBase($this->toBinary(), BinaryUtil::BASE58)), '0', '1'); + } + + /** + * Returns the identifier as a base32 case insensitive string. + */ + public function toBase32(): string + { + $uid = bin2hex($this->toBinary()); + $uid = sprintf('%02s%04s%04s%04s%04s%04s%04s', + base_convert(substr($uid, 0, 2), 16, 32), + base_convert(substr($uid, 2, 5), 16, 32), + base_convert(substr($uid, 7, 5), 16, 32), + base_convert(substr($uid, 12, 5), 16, 32), + base_convert(substr($uid, 17, 5), 16, 32), + base_convert(substr($uid, 22, 5), 16, 32), + base_convert(substr($uid, 27, 5), 16, 32) + ); + + return strtr($uid, 'abcdefghijklmnopqrstuv', 'ABCDEFGHJKMNPQRSTVWXYZ'); + } + + /** + * Returns the identifier as a RFC4122 case insensitive string. + */ + public function toRfc4122(): string + { + // don't use uuid_unparse(), it's slower + $uuid = bin2hex($this->toBinary()); + $uuid = substr_replace($uuid, '-', 8, 0); + $uuid = substr_replace($uuid, '-', 13, 0); + $uuid = substr_replace($uuid, '-', 18, 0); + + return substr_replace($uuid, '-', 23, 0); + } + + /** + * Returns whether the argument is an AbstractUid and contains the same value as the current instance. + */ + public function equals(mixed $other): bool + { + if (!$other instanceof self) { + return false; + } + + return $this->uid === $other->uid; + } + + public function compare(self $other): int + { + return (\strlen($this->uid) - \strlen($other->uid)) ?: ($this->uid <=> $other->uid); + } + + public function __toString(): string + { + return $this->uid; + } + + public function jsonSerialize(): string + { + return $this->uid; + } +} diff --git a/src/ncc/ThirdParty/Symfony/uid/BinaryUtil.php b/src/ncc/ThirdParty/Symfony/uid/BinaryUtil.php new file mode 100644 index 0000000..ea14627 --- /dev/null +++ b/src/ncc/ThirdParty/Symfony/uid/BinaryUtil.php @@ -0,0 +1,175 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ncc\Symfony\Component\Uid; + +/** + * @internal + * + * @author Nicolas Grekas
+ */
+class BinaryUtil
+{
+ public const BASE10 = [
+ '' => '0123456789',
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ ];
+
+ public const BASE58 = [
+ '' => '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
+ 1 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 'A' => 9,
+ 'B' => 10, 'C' => 11, 'D' => 12, 'E' => 13, 'F' => 14, 'G' => 15,
+ 'H' => 16, 'J' => 17, 'K' => 18, 'L' => 19, 'M' => 20, 'N' => 21,
+ 'P' => 22, 'Q' => 23, 'R' => 24, 'S' => 25, 'T' => 26, 'U' => 27,
+ 'V' => 28, 'W' => 29, 'X' => 30, 'Y' => 31, 'Z' => 32, 'a' => 33,
+ 'b' => 34, 'c' => 35, 'd' => 36, 'e' => 37, 'f' => 38, 'g' => 39,
+ 'h' => 40, 'i' => 41, 'j' => 42, 'k' => 43, 'm' => 44, 'n' => 45,
+ 'o' => 46, 'p' => 47, 'q' => 48, 'r' => 49, 's' => 50, 't' => 51,
+ 'u' => 52, 'v' => 53, 'w' => 54, 'x' => 55, 'y' => 56, 'z' => 57,
+ ];
+
+ // https://tools.ietf.org/html/rfc4122#section-4.1.4
+ // 0x01b21dd213814000 is the number of 100-ns intervals between the
+ // UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
+ private const TIME_OFFSET_INT = 0x01B21DD213814000;
+ private const TIME_OFFSET_BIN = "\x01\xb2\x1d\xd2\x13\x81\x40\x00";
+ private const TIME_OFFSET_COM1 = "\xfe\x4d\xe2\x2d\xec\x7e\xbf\xff";
+ private const TIME_OFFSET_COM2 = "\xfe\x4d\xe2\x2d\xec\x7e\xc0\x00";
+
+ public static function toBase(string $bytes, array $map): string
+ {
+ $base = \strlen($alphabet = $map['']);
+ $bytes = array_values(unpack(\PHP_INT_SIZE >= 8 ? 'n*' : 'C*', $bytes));
+ $digits = '';
+
+ while ($count = \count($bytes)) {
+ $quotient = [];
+ $remainder = 0;
+
+ for ($i = 0; $i !== $count; ++$i) {
+ $carry = $bytes[$i] + ($remainder << (\PHP_INT_SIZE >= 8 ? 16 : 8));
+ $digit = intdiv($carry, $base);
+ $remainder = $carry % $base;
+
+ if ($digit || $quotient) {
+ $quotient[] = $digit;
+ }
+ }
+
+ $digits = $alphabet[$remainder].$digits;
+ $bytes = $quotient;
+ }
+
+ return $digits;
+ }
+
+ public static function fromBase(string $digits, array $map): string
+ {
+ $base = \strlen($map['']);
+ $count = \strlen($digits);
+ $bytes = [];
+
+ while ($count) {
+ $quotient = [];
+ $remainder = 0;
+
+ for ($i = 0; $i !== $count; ++$i) {
+ $carry = ($bytes ? $digits[$i] : $map[$digits[$i]]) + $remainder * $base;
+
+ if (\PHP_INT_SIZE >= 8) {
+ $digit = $carry >> 16;
+ $remainder = $carry & 0xFFFF;
+ } else {
+ $digit = $carry >> 8;
+ $remainder = $carry & 0xFF;
+ }
+
+ if ($digit || $quotient) {
+ $quotient[] = $digit;
+ }
+ }
+
+ $bytes[] = $remainder;
+ $count = \count($digits = $quotient);
+ }
+
+ return pack(\PHP_INT_SIZE >= 8 ? 'n*' : 'C*', ...array_reverse($bytes));
+ }
+
+ public static function add(string $a, string $b): string
+ {
+ $carry = 0;
+ for ($i = 7; 0 <= $i; --$i) {
+ $carry += \ord($a[$i]) + \ord($b[$i]);
+ $a[$i] = \chr($carry & 0xFF);
+ $carry >>= 8;
+ }
+
+ return $a;
+ }
+
+ /**
+ * @param string $time Count of 100-nanosecond intervals since the UUID epoch 1582-10-15 00:00:00 in hexadecimal
+ */
+ public static function hexToDateTime(string $time): \DateTimeImmutable
+ {
+ if (\PHP_INT_SIZE >= 8) {
+ $time = (string) (hexdec($time) - self::TIME_OFFSET_INT);
+ } else {
+ $time = str_pad(hex2bin($time), 8, "\0", \STR_PAD_LEFT);
+
+ if (self::TIME_OFFSET_BIN <= $time) {
+ $time = self::add($time, self::TIME_OFFSET_COM2);
+ $time[0] = $time[0] & "\x7F";
+ $time = self::toBase($time, self::BASE10);
+ } else {
+ $time = self::add($time, self::TIME_OFFSET_COM1);
+ $time = '-'.self::toBase($time ^ "\xff\xff\xff\xff\xff\xff\xff\xff", self::BASE10);
+ }
+ }
+
+ if (9 > \strlen($time)) {
+ $time = '-' === $time[0] ? '-'.str_pad(substr($time, 1), 8, '0', \STR_PAD_LEFT) : str_pad($time, 8, '0', \STR_PAD_LEFT);
+ }
+
+ return \DateTimeImmutable::createFromFormat('U.u?', substr_replace($time, '.', -7, 0));
+ }
+
+ /**
+ * @return string Count of 100-nanosecond intervals since the UUID epoch 1582-10-15 00:00:00 in hexadecimal
+ */
+ public static function dateTimeToHex(\DateTimeInterface $time): string
+ {
+ if (\PHP_INT_SIZE >= 8) {
+ if (-self::TIME_OFFSET_INT > $time = (int) $time->format('Uu0')) {
+ throw new \InvalidArgumentException('The given UUID date cannot be earlier than 1582-10-15.');
+ }
+
+ return str_pad(dechex(self::TIME_OFFSET_INT + $time), 16, '0', \STR_PAD_LEFT);
+ }
+
+ $time = $time->format('Uu0');
+ $negative = '-' === $time[0];
+ if ($negative && self::TIME_OFFSET_INT < $time = substr($time, 1)) {
+ throw new \InvalidArgumentException('The given UUID date cannot be earlier than 1582-10-15.');
+ }
+ $time = self::fromBase($time, self::BASE10);
+ $time = str_pad($time, 8, "\0", \STR_PAD_LEFT);
+
+ if ($negative) {
+ $time = self::add($time, self::TIME_OFFSET_COM1) ^ "\xff\xff\xff\xff\xff\xff\xff\xff";
+ } else {
+ $time = self::add($time, self::TIME_OFFSET_BIN);
+ }
+
+ return bin2hex($time);
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/Factory/NameBasedUuidFactory.php b/src/ncc/ThirdParty/Symfony/uid/Factory/NameBasedUuidFactory.php
new file mode 100644
index 0000000..d1231fe
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/Factory/NameBasedUuidFactory.php
@@ -0,0 +1,44 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ncc\Symfony\Component\Uid\Factory;
+
+use ncc\Symfony\Component\Uid\Uuid;
+use ncc\Symfony\Component\Uid\UuidV3;
+use ncc\Symfony\Component\Uid\UuidV5;
+
+class NameBasedUuidFactory
+{
+ private string $class;
+ private Uuid $namespace;
+
+ public function __construct(string $class, Uuid $namespace)
+ {
+ $this->class = $class;
+ $this->namespace = $namespace;
+ }
+
+ public function create(string $name): UuidV5|UuidV3
+ {
+ switch ($class = $this->class) {
+ case UuidV5::class: return Uuid::v5($this->namespace, $name);
+ case UuidV3::class: return Uuid::v3($this->namespace, $name);
+ }
+
+ if (is_subclass_of($class, UuidV5::class)) {
+ $uuid = Uuid::v5($this->namespace, $name);
+ } else {
+ $uuid = Uuid::v3($this->namespace, $name);
+ }
+
+ return new $class($uuid);
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/Factory/RandomBasedUuidFactory.php b/src/ncc/ThirdParty/Symfony/uid/Factory/RandomBasedUuidFactory.php
new file mode 100644
index 0000000..b3db863
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/Factory/RandomBasedUuidFactory.php
@@ -0,0 +1,31 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ncc\Symfony\Component\Uid\Factory;
+
+use ncc\Symfony\Component\Uid\UuidV4;
+
+class RandomBasedUuidFactory
+{
+ private string $class;
+
+ public function __construct(string $class)
+ {
+ $this->class = $class;
+ }
+
+ public function create(): UuidV4
+ {
+ $class = $this->class;
+
+ return new $class();
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/Factory/TimeBasedUuidFactory.php b/src/ncc/ThirdParty/Symfony/uid/Factory/TimeBasedUuidFactory.php
new file mode 100644
index 0000000..203a786
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/Factory/TimeBasedUuidFactory.php
@@ -0,0 +1,39 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ncc\Symfony\Component\Uid\Factory;
+
+use ncc\Symfony\Component\Uid\Uuid;
+use ncc\Symfony\Component\Uid\UuidV1;
+use ncc\Symfony\Component\Uid\UuidV6;
+
+class TimeBasedUuidFactory
+{
+ private string $class;
+ private ?Uuid $node;
+
+ public function __construct(string $class, Uuid $node = null)
+ {
+ $this->class = $class;
+ $this->node = $node;
+ }
+
+ public function create(\DateTimeInterface $time = null): UuidV6|UuidV1
+ {
+ $class = $this->class;
+
+ if (null === $time && null === $this->node) {
+ return new $class();
+ }
+
+ return new $class($class::generate($time, $this->node));
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/Factory/UlidFactory.php b/src/ncc/ThirdParty/Symfony/uid/Factory/UlidFactory.php
new file mode 100644
index 0000000..e777d6e
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/Factory/UlidFactory.php
@@ -0,0 +1,22 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ncc\Symfony\Component\Uid\Factory;
+
+use ncc\Symfony\Component\Uid\Ulid;
+
+class UlidFactory
+{
+ public function create(\DateTimeInterface $time = null): Ulid
+ {
+ return new Ulid(null === $time ? null : Ulid::generate($time));
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/Factory/UuidFactory.php b/src/ncc/ThirdParty/Symfony/uid/Factory/UuidFactory.php
new file mode 100644
index 0000000..7159702
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/Factory/UuidFactory.php
@@ -0,0 +1,95 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ncc\Symfony\Component\Uid\Factory;
+
+use ncc\Symfony\Component\Uid\Uuid;
+use ncc\Symfony\Component\Uid\UuidV1;
+use ncc\Symfony\Component\Uid\UuidV4;
+use ncc\Symfony\Component\Uid\UuidV5;
+use ncc\Symfony\Component\Uid\UuidV6;
+
+class UuidFactory
+{
+ private string $defaultClass;
+ private string $timeBasedClass;
+ private string $nameBasedClass;
+ private string $randomBasedClass;
+ private ?Uuid $timeBasedNode;
+ private ?Uuid $nameBasedNamespace;
+
+ public function __construct(string|int $defaultClass = UuidV6::class, string|int $timeBasedClass = UuidV6::class, string|int $nameBasedClass = UuidV5::class, string|int $randomBasedClass = UuidV4::class, Uuid|string $timeBasedNode = null, Uuid|string $nameBasedNamespace = null)
+ {
+ if (null !== $timeBasedNode && !$timeBasedNode instanceof Uuid) {
+ $timeBasedNode = Uuid::fromString($timeBasedNode);
+ }
+
+ if (null !== $nameBasedNamespace) {
+ $nameBasedNamespace = $this->getNamespace($nameBasedNamespace);
+ }
+
+ $this->defaultClass = is_numeric($defaultClass) ? Uuid::class.'V'.$defaultClass : $defaultClass;
+ $this->timeBasedClass = is_numeric($timeBasedClass) ? Uuid::class.'V'.$timeBasedClass : $timeBasedClass;
+ $this->nameBasedClass = is_numeric($nameBasedClass) ? Uuid::class.'V'.$nameBasedClass : $nameBasedClass;
+ $this->randomBasedClass = is_numeric($randomBasedClass) ? Uuid::class.'V'.$randomBasedClass : $randomBasedClass;
+ $this->timeBasedNode = $timeBasedNode;
+ $this->nameBasedNamespace = $nameBasedNamespace;
+ }
+
+ public function create(): UuidV6|UuidV4|UuidV1
+ {
+ $class = $this->defaultClass;
+
+ return new $class();
+ }
+
+ public function randomBased(): RandomBasedUuidFactory
+ {
+ return new RandomBasedUuidFactory($this->randomBasedClass);
+ }
+
+ public function timeBased(Uuid|string $node = null): TimeBasedUuidFactory
+ {
+ $node ??= $this->timeBasedNode;
+
+ if (null !== $node && !$node instanceof Uuid) {
+ $node = Uuid::fromString($node);
+ }
+
+ return new TimeBasedUuidFactory($this->timeBasedClass, $node);
+ }
+
+ public function nameBased(Uuid|string $namespace = null): NameBasedUuidFactory
+ {
+ $namespace ??= $this->nameBasedNamespace;
+
+ if (null === $namespace) {
+ throw new \LogicException(sprintf('A namespace should be defined when using "%s()".', __METHOD__));
+ }
+
+ return new NameBasedUuidFactory($this->nameBasedClass, $this->getNamespace($namespace));
+ }
+
+ private function getNamespace(Uuid|string $namespace): Uuid
+ {
+ if ($namespace instanceof Uuid) {
+ return $namespace;
+ }
+
+ return match ($namespace) {
+ 'dns' => new UuidV1(Uuid::NAMESPACE_DNS),
+ 'url' => new UuidV1(Uuid::NAMESPACE_URL),
+ 'oid' => new UuidV1(Uuid::NAMESPACE_OID),
+ 'x500' => new UuidV1(Uuid::NAMESPACE_X500),
+ default => Uuid::fromString($namespace),
+ };
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/LICENSE b/src/ncc/ThirdParty/Symfony/uid/LICENSE
new file mode 100644
index 0000000..406242f
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2020-2022 Fabien Potencier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/src/ncc/ThirdParty/Symfony/uid/NilUlid.php b/src/ncc/ThirdParty/Symfony/uid/NilUlid.php
new file mode 100644
index 0000000..5f03354
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/NilUlid.php
@@ -0,0 +1,20 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ncc\Symfony\Component\Uid;
+
+class NilUlid extends Ulid
+{
+ public function __construct()
+ {
+ $this->uid = parent::NIL;
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/NilUuid.php b/src/ncc/ThirdParty/Symfony/uid/NilUuid.php
new file mode 100644
index 0000000..ba97bb2
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/NilUuid.php
@@ -0,0 +1,25 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ncc\Symfony\Component\Uid;
+
+/**
+ * @author Grégoire Pineau
+ */
+class Ulid extends AbstractUid
+{
+ protected const NIL = '00000000000000000000000000';
+
+ private static string $time = '';
+ private static array $rand = [];
+
+ public function __construct(string $ulid = null)
+ {
+ if (null === $ulid) {
+ $this->uid = static::generate();
+
+ return;
+ }
+
+ if (self::NIL === $ulid) {
+ $this->uid = $ulid;
+
+ return;
+ }
+
+ if (!self::isValid($ulid)) {
+ throw new \InvalidArgumentException(sprintf('Invalid ULID: "%s".', $ulid));
+ }
+
+ $this->uid = strtoupper($ulid);
+ }
+
+ public static function isValid(string $ulid): bool
+ {
+ if (26 !== \strlen($ulid)) {
+ return false;
+ }
+
+ if (26 !== strspn($ulid, '0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz')) {
+ return false;
+ }
+
+ return $ulid[0] <= '7';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function fromString(string $ulid): static
+ {
+ if (36 === \strlen($ulid) && Uuid::isValid($ulid)) {
+ $ulid = (new Uuid($ulid))->toBinary();
+ } elseif (22 === \strlen($ulid) && 22 === strspn($ulid, BinaryUtil::BASE58[''])) {
+ $ulid = str_pad(BinaryUtil::fromBase($ulid, BinaryUtil::BASE58), 16, "\0", \STR_PAD_LEFT);
+ }
+
+ if (16 !== \strlen($ulid)) {
+ if (self::NIL === $ulid) {
+ return new NilUlid();
+ }
+
+ return new static($ulid);
+ }
+
+ $ulid = bin2hex($ulid);
+ $ulid = sprintf('%02s%04s%04s%04s%04s%04s%04s',
+ base_convert(substr($ulid, 0, 2), 16, 32),
+ base_convert(substr($ulid, 2, 5), 16, 32),
+ base_convert(substr($ulid, 7, 5), 16, 32),
+ base_convert(substr($ulid, 12, 5), 16, 32),
+ base_convert(substr($ulid, 17, 5), 16, 32),
+ base_convert(substr($ulid, 22, 5), 16, 32),
+ base_convert(substr($ulid, 27, 5), 16, 32)
+ );
+
+ if (self::NIL === $ulid) {
+ return new NilUlid();
+ }
+
+ $u = new static(self::NIL);
+ $u->uid = strtr($ulid, 'abcdefghijklmnopqrstuv', 'ABCDEFGHJKMNPQRSTVWXYZ');
+
+ return $u;
+ }
+
+ public function toBinary(): string
+ {
+ $ulid = strtr($this->uid, 'ABCDEFGHJKMNPQRSTVWXYZ', 'abcdefghijklmnopqrstuv');
+
+ $ulid = sprintf('%02s%05s%05s%05s%05s%05s%05s',
+ base_convert(substr($ulid, 0, 2), 32, 16),
+ base_convert(substr($ulid, 2, 4), 32, 16),
+ base_convert(substr($ulid, 6, 4), 32, 16),
+ base_convert(substr($ulid, 10, 4), 32, 16),
+ base_convert(substr($ulid, 14, 4), 32, 16),
+ base_convert(substr($ulid, 18, 4), 32, 16),
+ base_convert(substr($ulid, 22, 4), 32, 16)
+ );
+
+ return hex2bin($ulid);
+ }
+
+ public function toBase32(): string
+ {
+ return $this->uid;
+ }
+
+ public function getDateTime(): \DateTimeImmutable
+ {
+ $time = strtr(substr($this->uid, 0, 10), 'ABCDEFGHJKMNPQRSTVWXYZ', 'abcdefghijklmnopqrstuv');
+
+ if (\PHP_INT_SIZE >= 8) {
+ $time = (string) hexdec(base_convert($time, 32, 16));
+ } else {
+ $time = sprintf('%02s%05s%05s',
+ base_convert(substr($time, 0, 2), 32, 16),
+ base_convert(substr($time, 2, 4), 32, 16),
+ base_convert(substr($time, 6, 4), 32, 16)
+ );
+ $time = BinaryUtil::toBase(hex2bin($time), BinaryUtil::BASE10);
+ }
+
+ if (4 > \strlen($time)) {
+ $time = str_pad($time, 4, '0', \STR_PAD_LEFT);
+ }
+
+ return \DateTimeImmutable::createFromFormat('U.u', substr_replace($time, '.', -3, 0));
+ }
+
+ public static function generate(\DateTimeInterface $time = null): string
+ {
+ if (null === $time) {
+ return self::doGenerate();
+ }
+
+ if (0 > $time = substr($time->format('Uu'), 0, -3)) {
+ throw new \InvalidArgumentException('The timestamp must be positive.');
+ }
+
+ return self::doGenerate($time);
+ }
+
+ private static function doGenerate(string $mtime = null): string
+ {
+ if (null === $time = $mtime) {
+ $time = microtime(false);
+ $time = substr($time, 11).substr($time, 2, 3);
+ }
+
+ if ($time !== self::$time) {
+ $r = unpack('nr1/nr2/nr3/nr4/nr', random_bytes(10));
+ $r['r1'] |= ($r['r'] <<= 4) & 0xF0000;
+ $r['r2'] |= ($r['r'] <<= 4) & 0xF0000;
+ $r['r3'] |= ($r['r'] <<= 4) & 0xF0000;
+ $r['r4'] |= ($r['r'] <<= 4) & 0xF0000;
+ unset($r['r']);
+ self::$rand = array_values($r);
+ self::$time = $time;
+ } elseif ([0xFFFFF, 0xFFFFF, 0xFFFFF, 0xFFFFF] === self::$rand) {
+ if (null === $mtime) {
+ usleep(100);
+ } else {
+ self::$rand = [0, 0, 0, 0];
+ }
+
+ return self::doGenerate($mtime);
+ } else {
+ for ($i = 3; $i >= 0 && 0xFFFFF === self::$rand[$i]; --$i) {
+ self::$rand[$i] = 0;
+ }
+
+ ++self::$rand[$i];
+ }
+
+ if (\PHP_INT_SIZE >= 8) {
+ $time = base_convert($time, 10, 32);
+ } else {
+ $time = str_pad(bin2hex(BinaryUtil::fromBase($time, BinaryUtil::BASE10)), 12, '0', \STR_PAD_LEFT);
+ $time = sprintf('%s%04s%04s',
+ base_convert(substr($time, 0, 2), 16, 32),
+ base_convert(substr($time, 2, 5), 16, 32),
+ base_convert(substr($time, 7, 5), 16, 32)
+ );
+ }
+
+ return strtr(sprintf('%010s%04s%04s%04s%04s',
+ $time,
+ base_convert(self::$rand[0], 10, 32),
+ base_convert(self::$rand[1], 10, 32),
+ base_convert(self::$rand[2], 10, 32),
+ base_convert(self::$rand[3], 10, 32)
+ ), 'abcdefghijklmnopqrstuv', 'ABCDEFGHJKMNPQRSTVWXYZ');
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/Uuid.php b/src/ncc/ThirdParty/Symfony/uid/Uuid.php
new file mode 100644
index 0000000..86e1609
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/Uuid.php
@@ -0,0 +1,146 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ncc\Symfony\Component\Uid;
+
+/**
+ * @author Grégoire Pineau
+ */
+class UuidV6 extends Uuid
+{
+ protected const TYPE = 6;
+
+ private static string $node;
+
+ public function __construct(string $uuid = null)
+ {
+ if (null === $uuid) {
+ $this->uid = static::generate();
+ } else {
+ parent::__construct($uuid);
+ }
+ }
+
+ public function getDateTime(): \DateTimeImmutable
+ {
+ return BinaryUtil::hexToDateTime('0'.substr($this->uid, 0, 8).substr($this->uid, 9, 4).substr($this->uid, 15, 3));
+ }
+
+ public function getNode(): string
+ {
+ return substr($this->uid, 24);
+ }
+
+ public static function generate(\DateTimeInterface $time = null, Uuid $node = null): string
+ {
+ $uuidV1 = UuidV1::generate($time, $node);
+ $uuid = substr($uuidV1, 15, 3).substr($uuidV1, 9, 4).$uuidV1[0].'-'.substr($uuidV1, 1, 4).'-6'.substr($uuidV1, 5, 3).substr($uuidV1, 18, 6);
+
+ if ($node) {
+ return $uuid.substr($uuidV1, 24);
+ }
+
+ // uuid_create() returns a stable "node" that can leak the MAC of the host, but
+ // UUIDv6 prefers a truly random number here, let's XOR both to preserve the entropy
+
+ if (!isset(self::$node)) {
+ $seed = [random_int(0, 0xFFFFFF), random_int(0, 0xFFFFFF)];
+ $node = unpack('N2', hex2bin('00'.substr($uuidV1, 24, 6)).hex2bin('00'.substr($uuidV1, 30)));
+ self::$node = sprintf('%06x%06x', ($seed[0] ^ $node[1]) | 0x010000, $seed[1] ^ $node[2]);
+ }
+
+ return $uuid.self::$node;
+ }
+}
diff --git a/src/ncc/ThirdParty/Symfony/uid/VERSION b/src/ncc/ThirdParty/Symfony/uid/VERSION
new file mode 100644
index 0000000..358e78e
--- /dev/null
+++ b/src/ncc/ThirdParty/Symfony/uid/VERSION
@@ -0,0 +1 @@
+6.1.0
\ No newline at end of file
diff --git a/src/ncc/autoload.php b/src/ncc/autoload.php
index 12449b8..7379014 100644
--- a/src/ncc/autoload.php
+++ b/src/ncc/autoload.php
@@ -77,6 +77,22 @@ spl_autoload_register(
'ncc\\symfony\\component\\process\\pipes\\windowspipes' => '/ThirdParty/Symfony/Process/Pipes/WindowsPipes.php',
'ncc\\symfony\\component\\process\\process' => '/ThirdParty/Symfony/Process/Process.php',
'ncc\\symfony\\component\\process\\processutils' => '/ThirdParty/Symfony/Process/ProcessUtils.php',
+ 'ncc\\symfony\\component\\uid\\abstractuid' => '/ThirdParty/Symfony/uid/AbstractUid.php',
+ 'ncc\\symfony\\component\\uid\\binaryutil' => '/ThirdParty/Symfony/uid/BinaryUtil.php',
+ 'ncc\\symfony\\component\\uid\\factory\\namebaseduuidfactory' => '/ThirdParty/Symfony/uid/Factory/NameBasedUuidFactory.php',
+ 'ncc\\symfony\\component\\uid\\factory\\randombaseduuidfactory' => '/ThirdParty/Symfony/uid/Factory/RandomBasedUuidFactory.php',
+ 'ncc\\symfony\\component\\uid\\factory\\timebaseduuidfactory' => '/ThirdParty/Symfony/uid/Factory/TimeBasedUuidFactory.php',
+ 'ncc\\symfony\\component\\uid\\factory\\ulidfactory' => '/ThirdParty/Symfony/uid/Factory/UlidFactory.php',
+ 'ncc\\symfony\\component\\uid\\factory\\uuidfactory' => '/ThirdParty/Symfony/uid/Factory/UuidFactory.php',
+ 'ncc\\symfony\\component\\uid\\nilulid' => '/ThirdParty/Symfony/uid/NilUlid.php',
+ 'ncc\\symfony\\component\\uid\\niluuid' => '/ThirdParty/Symfony/uid/NilUuid.php',
+ 'ncc\\symfony\\component\\uid\\ulid' => '/ThirdParty/Symfony/uid/Ulid.php',
+ 'ncc\\symfony\\component\\uid\\uuid' => '/ThirdParty/Symfony/uid/Uuid.php',
+ 'ncc\\symfony\\component\\uid\\uuidv1' => '/ThirdParty/Symfony/uid/UuidV1.php',
+ 'ncc\\symfony\\component\\uid\\uuidv3' => '/ThirdParty/Symfony/uid/UuidV3.php',
+ 'ncc\\symfony\\component\\uid\\uuidv4' => '/ThirdParty/Symfony/uid/UuidV4.php',
+ 'ncc\\symfony\\component\\uid\\uuidv5' => '/ThirdParty/Symfony/uid/UuidV5.php',
+ 'ncc\\symfony\\component\\uid\\uuidv6' => '/ThirdParty/Symfony/uid/UuidV6.php',
'ncc\\utilities\\functions' => '/Utilities/Functions.php',
'ncc\\utilities\\pathfinder' => '/Utilities/PathFinder.php',
'ncc\\utilities\\resolver' => '/Utilities/Resolver.php',