summaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/uuid/src/Builder
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ramsey/uuid/src/Builder')
-rw-r--r--vendor/ramsey/uuid/src/Builder/BuilderCollection.php80
-rw-r--r--vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php26
-rw-r--r--vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php76
-rw-r--r--vendor/ramsey/uuid/src/Builder/FallbackBuilder.php74
-rw-r--r--vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php39
5 files changed, 295 insertions, 0 deletions
diff --git a/vendor/ramsey/uuid/src/Builder/BuilderCollection.php b/vendor/ramsey/uuid/src/Builder/BuilderCollection.php
new file mode 100644
index 0000000..89fa1e3
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Builder/BuilderCollection.php
@@ -0,0 +1,80 @@
+<?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\Builder;
+
+use Ramsey\Collection\AbstractCollection;
+use Ramsey\Uuid\Converter\Number\GenericNumberConverter;
+use Ramsey\Uuid\Converter\Time\GenericTimeConverter;
+use Ramsey\Uuid\Converter\Time\PhpTimeConverter;
+use Ramsey\Uuid\Guid\GuidBuilder;
+use Ramsey\Uuid\Math\BrickMathCalculator;
+use Ramsey\Uuid\Nonstandard\UuidBuilder as NonstandardUuidBuilder;
+use Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder;
+use Traversable;
+
+/**
+ * A collection of UuidBuilderInterface objects
+ *
+ * @extends AbstractCollection<UuidBuilderInterface>
+ */
+class BuilderCollection extends AbstractCollection
+{
+ public function getType(): string
+ {
+ return UuidBuilderInterface::class;
+ }
+
+ /**
+ * @psalm-mutation-free
+ * @psalm-suppress ImpureMethodCall
+ * @psalm-suppress InvalidTemplateParam
+ */
+ public function getIterator(): Traversable
+ {
+ return parent::getIterator();
+ }
+
+ /**
+ * Re-constructs the object from its serialized form
+ *
+ * @param string $serialized The serialized PHP string to unserialize into
+ * a UuidInterface instance
+ *
+ * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
+ * @psalm-suppress RedundantConditionGivenDocblockType
+ */
+ public function unserialize($serialized): void
+ {
+ /** @var array<array-key, UuidBuilderInterface> $data */
+ $data = unserialize($serialized, [
+ 'allowed_classes' => [
+ BrickMathCalculator::class,
+ GenericNumberConverter::class,
+ GenericTimeConverter::class,
+ GuidBuilder::class,
+ NonstandardUuidBuilder::class,
+ PhpTimeConverter::class,
+ Rfc4122UuidBuilder::class,
+ ],
+ ]);
+
+ $this->data = array_filter(
+ $data,
+ function ($unserialized): bool {
+ return $unserialized instanceof UuidBuilderInterface;
+ }
+ );
+ }
+}
diff --git a/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php
new file mode 100644
index 0000000..7c4a6f8
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php
@@ -0,0 +1,26 @@
+<?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\Builder;
+
+use Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder;
+
+/**
+ * @deprecated Transition to {@see Rfc4122UuidBuilder}.
+ *
+ * @psalm-immutable
+ */
+class DefaultUuidBuilder extends Rfc4122UuidBuilder
+{
+}
diff --git a/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php
new file mode 100644
index 0000000..23931e4
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php
@@ -0,0 +1,76 @@
+<?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\Builder;
+
+use Ramsey\Uuid\Codec\CodecInterface;
+use Ramsey\Uuid\Converter\NumberConverterInterface;
+use Ramsey\Uuid\Converter\Time\DegradedTimeConverter;
+use Ramsey\Uuid\Converter\TimeConverterInterface;
+use Ramsey\Uuid\DegradedUuid;
+use Ramsey\Uuid\Rfc4122\Fields as Rfc4122Fields;
+use Ramsey\Uuid\UuidInterface;
+
+/**
+ * @deprecated DegradedUuid instances are no longer necessary to support 32-bit
+ * systems. Transition to {@see DefaultUuidBuilder}.
+ *
+ * @psalm-immutable
+ */
+class DegradedUuidBuilder implements UuidBuilderInterface
+{
+ /**
+ * @var NumberConverterInterface
+ */
+ private $numberConverter;
+
+ /**
+ * @var TimeConverterInterface
+ */
+ private $timeConverter;
+
+ /**
+ * @param NumberConverterInterface $numberConverter The number converter to
+ * use when constructing the DegradedUuid
+ * @param TimeConverterInterface|null $timeConverter The time converter to use
+ * for converting timestamps extracted from a UUID to Unix timestamps
+ */
+ public function __construct(
+ NumberConverterInterface $numberConverter,
+ ?TimeConverterInterface $timeConverter = null
+ ) {
+ $this->numberConverter = $numberConverter;
+ $this->timeConverter = $timeConverter ?: new DegradedTimeConverter();
+ }
+
+ /**
+ * Builds and returns a DegradedUuid
+ *
+ * @param CodecInterface $codec The codec to use for building this DegradedUuid instance
+ * @param string $bytes The byte string from which to construct a UUID
+ *
+ * @return DegradedUuid The DegradedUuidBuild returns an instance of Ramsey\Uuid\DegradedUuid
+ *
+ * @psalm-pure
+ */
+ public function build(CodecInterface $codec, string $bytes): UuidInterface
+ {
+ return new DegradedUuid(
+ new Rfc4122Fields($bytes),
+ $this->numberConverter,
+ $codec,
+ $this->timeConverter
+ );
+ }
+}
diff --git a/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php b/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php
new file mode 100644
index 0000000..470d2f7
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php
@@ -0,0 +1,74 @@
+<?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\Builder;
+
+use Ramsey\Uuid\Codec\CodecInterface;
+use Ramsey\Uuid\Exception\BuilderNotFoundException;
+use Ramsey\Uuid\Exception\UnableToBuildUuidException;
+use Ramsey\Uuid\UuidInterface;
+
+/**
+ * FallbackBuilder builds a UUID by stepping through a list of UUID builders
+ * until a UUID can be constructed without exceptions
+ *
+ * @psalm-immutable
+ */
+class FallbackBuilder implements UuidBuilderInterface
+{
+ /**
+ * @var BuilderCollection
+ */
+ private $builders;
+
+ /**
+ * @param BuilderCollection $builders An array of UUID builders
+ */
+ public function __construct(BuilderCollection $builders)
+ {
+ $this->builders = $builders;
+ }
+
+ /**
+ * Builds and returns a UuidInterface instance using the first builder that
+ * succeeds
+ *
+ * @param CodecInterface $codec The codec to use for building this instance
+ * @param string $bytes The byte string from which to construct a UUID
+ *
+ * @return UuidInterface an instance of a UUID object
+ *
+ * @psalm-pure
+ */
+ public function build(CodecInterface $codec, string $bytes): UuidInterface
+ {
+ $lastBuilderException = null;
+
+ foreach ($this->builders as $builder) {
+ try {
+ return $builder->build($codec, $bytes);
+ } catch (UnableToBuildUuidException $exception) {
+ $lastBuilderException = $exception;
+
+ continue;
+ }
+ }
+
+ throw new BuilderNotFoundException(
+ 'Could not find a suitable builder for the provided codec and fields',
+ 0,
+ $lastBuilderException
+ );
+ }
+}
diff --git a/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php b/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php
new file mode 100644
index 0000000..8e58b2b
--- /dev/null
+++ b/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php
@@ -0,0 +1,39 @@
+<?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\Builder;
+
+use Ramsey\Uuid\Codec\CodecInterface;
+use Ramsey\Uuid\UuidInterface;
+
+/**
+ * A UUID builder builds instances of UuidInterface
+ *
+ * @psalm-immutable
+ */
+interface UuidBuilderInterface
+{
+ /**
+ * Builds and returns a UuidInterface
+ *
+ * @param CodecInterface $codec The codec to use for building this UuidInterface instance
+ * @param string $bytes The byte string from which to construct a UUID
+ *
+ * @return UuidInterface Implementations may choose to return more specific
+ * instances of UUIDs that implement UuidInterface
+ *
+ * @psalm-pure
+ */
+ public function build(CodecInterface $codec, string $bytes): UuidInterface;
+}