Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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\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
27
 *     systems. Transition to {@see DefaultUuidBuilder}.
28
 *
29
 * @psalm-immutable
30
 */
31
class DegradedUuidBuilder implements UuidBuilderInterface
32
{
33
    private TimeConverterInterface $timeConverter;
34
 
35
    /**
36
     * @param NumberConverterInterface $numberConverter The number converter to
37
     *     use when constructing the DegradedUuid
38
     * @param TimeConverterInterface|null $timeConverter The time converter to use
39
     *     for converting timestamps extracted from a UUID to Unix timestamps
40
     */
41
    public function __construct(
42
        private NumberConverterInterface $numberConverter,
43
        ?TimeConverterInterface $timeConverter = null
44
    ) {
45
        $this->timeConverter = $timeConverter ?: new DegradedTimeConverter();
46
    }
47
 
48
    /**
49
     * Builds and returns a DegradedUuid
50
     *
51
     * @param CodecInterface $codec The codec to use for building this DegradedUuid instance
52
     * @param string $bytes The byte string from which to construct a UUID
53
     *
54
     * @return DegradedUuid The DegradedUuidBuild returns an instance of Ramsey\Uuid\DegradedUuid
55
     *
56
     * @psalm-pure
57
     */
58
    public function build(CodecInterface $codec, string $bytes): UuidInterface
59
    {
60
        return new DegradedUuid(
61
            new Rfc4122Fields($bytes),
62
            $this->numberConverter,
63
            $codec,
64
            $this->timeConverter
65
        );
66
    }
67
}