diff options
author | Mario <mario@mariovavti.com> | 2021-01-13 09:50:53 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-01-13 09:50:53 +0000 |
commit | 5eefdc6485b2f6082f6fe5dfd6f1731fae7e3a2a (patch) | |
tree | 7521f4800e393538d19c393c6f495ea2d41cbf5a /vendor/ramsey/uuid/src/Builder | |
parent | 0bc4c7d1a0e4348018e533be600ad1c648fd97fb (diff) | |
parent | 4d2bcbc5837a7d99dc541595ca8087c335242af0 (diff) | |
download | volse-hubzilla-5.2.tar.gz volse-hubzilla-5.2.tar.bz2 volse-hubzilla-5.2.zip |
Merge branch '5.2RC'5.2
Diffstat (limited to 'vendor/ramsey/uuid/src/Builder')
5 files changed, 211 insertions, 63 deletions
diff --git a/vendor/ramsey/uuid/src/Builder/BuilderCollection.php b/vendor/ramsey/uuid/src/Builder/BuilderCollection.php new file mode 100644 index 000000000..b3e5f1dc9 --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/BuilderCollection.php @@ -0,0 +1,73 @@ +<?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\Collection\CollectionInterface; +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 + */ +class BuilderCollection extends AbstractCollection implements CollectionInterface +{ + 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 + */ + public function unserialize($serialized): void + { + /** @var mixed[] $data */ + $data = unserialize($serialized, [ + 'allowed_classes' => [ + BrickMathCalculator::class, + GenericNumberConverter::class, + GenericTimeConverter::class, + GuidBuilder::class, + NonstandardUuidBuilder::class, + PhpTimeConverter::class, + Rfc4122UuidBuilder::class, + ], + ]); + + $this->data = $data; + } +} diff --git a/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php index 20656acdf..2af4e867d 100644 --- a/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php +++ b/vendor/ramsey/uuid/src/Builder/DefaultUuidBuilder.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,48 +8,19 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Builder; -use Ramsey\Uuid\Codec\CodecInterface; -use Ramsey\Uuid\Converter\NumberConverterInterface; -use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder; /** - * DefaultUuidBuilder is the default UUID builder for ramsey/uuid; it builds - * instances of Uuid objects + * @deprecated Transition to {@see Rfc4122UuidBuilder}. + * + * @psalm-immutable */ -class DefaultUuidBuilder implements UuidBuilderInterface +class DefaultUuidBuilder extends Rfc4122UuidBuilder implements UuidBuilderInterface { - /** - * @var NumberConverterInterface - */ - private $converter; - - /** - * Constructs the DefaultUuidBuilder - * - * @param NumberConverterInterface $converter The number converter to use when constructing the Uuid - */ - public function __construct(NumberConverterInterface $converter) - { - $this->converter = $converter; - } - - /** - * Builds a Uuid - * - * @param CodecInterface $codec The codec to use for building this Uuid - * @param array $fields An array of fields from which to construct the Uuid; - * see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. - * @return Uuid - */ - public function build(CodecInterface $codec, array $fields) - { - return new Uuid($fields, $this->converter, $codec); - } } diff --git a/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php index 7edb6deb7..23931e416 100644 --- a/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php +++ b/vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,47 +8,69 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +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; /** - * DegradedUuidBuilder builds instances of DegradedUuid + * @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 $converter; + private $numberConverter; /** - * Constructs the DegradedUuidBuilder - * - * @param NumberConverterInterface $converter The number converter to use when constructing the DegradedUuid + * @var TimeConverterInterface */ - public function __construct(NumberConverterInterface $converter) - { - $this->converter = $converter; + 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 a DegradedUuid + * 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 * - * @param CodecInterface $codec The codec to use for building this DegradedUuid - * @param array $fields An array of fields from which to construct the DegradedUuid; - * see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. - * @return DegradedUuid + * @psalm-pure */ - public function build(CodecInterface $codec, array $fields) + public function build(CodecInterface $codec, string $bytes): UuidInterface { - return new DegradedUuid($fields, $this->converter, $codec); + 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 000000000..cfd4665ac --- /dev/null +++ b/vendor/ramsey/uuid/src/Builder/FallbackBuilder.php @@ -0,0 +1,75 @@ +<?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; + + /** @var UuidBuilderInterface $builder */ + 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 index e4e990109..8e58b2b43 100644 --- a/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php +++ b/vendor/ramsey/uuid/src/Builder/UuidBuilderInterface.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,28 +8,32 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Builder; use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\UuidInterface; /** - * UuidBuilderInterface builds instances UuidInterface + * A UUID builder builds instances of UuidInterface + * + * @psalm-immutable */ interface UuidBuilderInterface { /** - * Builds an instance of a UuidInterface + * Builds and returns a UuidInterface * * @param CodecInterface $codec The codec to use for building this UuidInterface instance - * @param array $fields An array of fields from which to construct a UuidInterface instance; - * see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. - * @return UuidInterface + * @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, array $fields); + public function build(CodecInterface $codec, string $bytes): UuidInterface; } |