Debian Codegraph @

vendor/ramsey/uuid/src/Rfc4122/UuidV8.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\Rfc4122;
16
17 use Ramsey\Uuid\Codec\CodecInterface;
18 use Ramsey\Uuid\Converter\NumberConverterInterface;
19 use Ramsey\Uuid\Converter\TimeConverterInterface;
20 use Ramsey\Uuid\Exception\InvalidArgumentException;
21 use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
22 use Ramsey\Uuid\Uuid;
23
24 /**
25 * Custom format, or version 8, UUIDs provide an RFC-compatible format for experimental or vendor-specific uses
26 *
27 * The only requirement for version 8 UUIDs is that the version and variant bits must be set. Otherwise, implementations
28 * are free to set the other bits according to their needs. As a result, the uniqueness of version 8 UUIDs is
29 * implementation-specific and should not be assumed.
30 *
31 * @link https://www.rfc-editor.org/rfc/rfc9562#section-5.8 RFC 9562, 5.8. UUID Version 8
32 *
33 * @immutable
34 */
35 final class UuidV8 extends Uuid implements UuidInterface
36 {
37 /**
38 * Creates a version 8 (custom format) UUID
39 *
40 * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID
41 * @param NumberConverterInterface $numberConverter The number converter to use for converting hex values to/from integers
42 * @param CodecInterface $codec The codec to use when encoding or decoding UUID strings
43 * @param TimeConverterInterface $timeConverter The time converter to use for converting timestamps extracted from a
44 * UUID to unix timestamps
45 */
46 public function __construct(
47 Rfc4122FieldsInterface $fields,
48 NumberConverterInterface $numberConverter,
49 CodecInterface $codec,
50 TimeConverterInterface $timeConverter,
51 ) {
52 if ($fields->getVersion() !== Uuid::UUID_TYPE_CUSTOM) {
53 throw new InvalidArgumentException(
54 'Fields used to create a UuidV8 must represent a version 8 (custom format) UUID',
55 );
56 }
57
58 parent::__construct($fields, $numberConverter, $codec, $timeConverter);
59 }
60 }