| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* This file is part of the ramsey/uuid library
|
|
|
5 |
*
|
|
|
6 |
* For the full copyright and license information, please view the LICENSE
|
|
|
7 |
* file that was distributed with this source code.
|
|
|
8 |
*
|
|
|
9 |
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
|
|
|
10 |
* @license http://opensource.org/licenses/MIT MIT
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
declare(strict_types=1);
|
|
|
14 |
|
|
|
15 |
namespace Ramsey\Uuid\Builder;
|
|
|
16 |
|
|
|
17 |
use Ramsey\Collection\AbstractCollection;
|
|
|
18 |
use Ramsey\Uuid\Converter\Number\GenericNumberConverter;
|
|
|
19 |
use Ramsey\Uuid\Converter\Time\GenericTimeConverter;
|
|
|
20 |
use Ramsey\Uuid\Converter\Time\PhpTimeConverter;
|
|
|
21 |
use Ramsey\Uuid\Guid\GuidBuilder;
|
|
|
22 |
use Ramsey\Uuid\Math\BrickMathCalculator;
|
|
|
23 |
use Ramsey\Uuid\Nonstandard\UuidBuilder as NonstandardUuidBuilder;
|
|
|
24 |
use Ramsey\Uuid\Rfc4122\UuidBuilder as Rfc4122UuidBuilder;
|
|
|
25 |
use Traversable;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* A collection of UuidBuilderInterface objects
|
|
|
29 |
*
|
|
|
30 |
* @deprecated this class has been deprecated, and will be removed in 5.0.0. The use-case for this class comes from
|
|
|
31 |
* a pre-`phpstan/phpstan` and pre-`vimeo/psalm` ecosystem, in which type safety had to be mostly enforced
|
|
|
32 |
* at runtime: that is no longer necessary, now that you can safely verify your code to be correct, and use
|
|
|
33 |
* more generic types like `iterable<T>` instead.
|
|
|
34 |
*
|
|
|
35 |
* @extends AbstractCollection<UuidBuilderInterface>
|
|
|
36 |
*/
|
|
|
37 |
class BuilderCollection extends AbstractCollection
|
|
|
38 |
{
|
|
|
39 |
public function getType(): string
|
|
|
40 |
{
|
|
|
41 |
return UuidBuilderInterface::class;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* @psalm-mutation-free
|
|
|
46 |
* @psalm-suppress ImpureMethodCall
|
|
|
47 |
* @psalm-suppress InvalidTemplateParam
|
|
|
48 |
*/
|
|
|
49 |
public function getIterator(): Traversable
|
|
|
50 |
{
|
|
|
51 |
return parent::getIterator();
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Re-constructs the object from its serialized form
|
|
|
56 |
*
|
|
|
57 |
* @param string $serialized The serialized PHP string to unserialize into
|
|
|
58 |
* a UuidInterface instance
|
|
|
59 |
*
|
|
|
60 |
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
|
|
|
61 |
* @psalm-suppress RedundantConditionGivenDocblockType
|
|
|
62 |
*/
|
|
|
63 |
public function unserialize($serialized): void
|
|
|
64 |
{
|
|
|
65 |
/** @var array<array-key, UuidBuilderInterface> $data */
|
|
|
66 |
$data = unserialize($serialized, [
|
|
|
67 |
'allowed_classes' => [
|
|
|
68 |
BrickMathCalculator::class,
|
|
|
69 |
GenericNumberConverter::class,
|
|
|
70 |
GenericTimeConverter::class,
|
|
|
71 |
GuidBuilder::class,
|
|
|
72 |
NonstandardUuidBuilder::class,
|
|
|
73 |
PhpTimeConverter::class,
|
|
|
74 |
Rfc4122UuidBuilder::class,
|
|
|
75 |
],
|
|
|
76 |
]);
|
|
|
77 |
|
|
|
78 |
$this->data = array_filter(
|
|
|
79 |
$data,
|
|
|
80 |
function ($unserialized): bool {
|
|
|
81 |
return $unserialized instanceof UuidBuilderInterface;
|
|
|
82 |
}
|
|
|
83 |
);
|
|
|
84 |
}
|
|
|
85 |
}
|