BuilderCollection.php 2.5 KB

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