Debian Codegraph @

vendor/ramsey/uuid/src/Builder/DegradedUuidBuilder.php

raw
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 <[email protected]>
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\Uuid\Codec\CodecInterface;
18 use Ramsey\Uuid\Converter\NumberConverterInterface;
19 use Ramsey\Uuid\Converter\Time\DegradedTimeConverter;
20 use Ramsey\Uuid\Converter\TimeConverterInterface;
21 use Ramsey\Uuid\DegradedUuid;
22 use Ramsey\Uuid\Rfc4122\Fields as Rfc4122Fields;
23 use Ramsey\Uuid\UuidInterface;
24
25 /**
26 * @deprecated DegradedUuid instances are no longer necessary to support 32-bit systems. Please transition to {@see DefaultUuidBuilder}.
27 *
28 * @immutable
29 */
30 class DegradedUuidBuilder implements UuidBuilderInterface
31 {
32 private TimeConverterInterface $timeConverter;
33
34 /**
35 * @param NumberConverterInterface $numberConverter The number converter to use when constructing the DegradedUuid
36 * @param TimeConverterInterface|null $timeConverter The time converter to use for converting timestamps extracted
37 * from a UUID to Unix timestamps
38 */
39 public function __construct(
40 private NumberConverterInterface $numberConverter,
41 ?TimeConverterInterface $timeConverter = null
42 ) {
43 $this->timeConverter = $timeConverter ?: new DegradedTimeConverter();
44 }
45
46 /**
47 * Builds and returns a DegradedUuid
48 *
49 * @param CodecInterface $codec The codec to use for building this DegradedUuid instance
50 * @param string $bytes The byte string from which to construct a UUID
51 *
52 * @return DegradedUuid The DegradedUuidBuild returns an instance of Ramsey\Uuid\DegradedUuid
53 *
54 * @phpstan-impure
55 */
56 public function build(CodecInterface $codec, string $bytes): UuidInterface
57 {
58 return new DegradedUuid(new Rfc4122Fields($bytes), $this->numberConverter, $codec, $this->timeConverter);
59 }
60 }