Debian Codegraph @

vendor/ramsey/uuid/src/Rfc4122/UuidV3.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 * Version 3 UUIDs are named-based, using a combination of a namespace and name that are hashed into a 128-bit unsigned
26 * integer using the MD5 hashing algorithm
27 *
28 * @link https://www.rfc-editor.org/rfc/rfc9562#section-5.3 RFC 9562, 5.3. UUID Version 3
29 *
30 * @immutable
31 */
32 final class UuidV3 extends Uuid implements UuidInterface
33 {
34 /**
35 * Creates a version 3 (name-based, MD5-hashed) UUID
36 *
37 * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID
38 * @param NumberConverterInterface $numberConverter The number converter to use for converting hex values to/from integers
39 * @param CodecInterface $codec The codec to use when encoding or decoding UUID strings
40 * @param TimeConverterInterface $timeConverter The time converter to use for converting timestamps extracted from a
41 * UUID to unix timestamps
42 */
43 public function __construct(
44 Rfc4122FieldsInterface $fields,
45 NumberConverterInterface $numberConverter,
46 CodecInterface $codec,
47 TimeConverterInterface $timeConverter,
48 ) {
49 if ($fields->getVersion() !== Uuid::UUID_TYPE_HASH_MD5) {
50 throw new InvalidArgumentException(
51 'Fields used to create a UuidV3 must represent a version 3 (name-based, MD5-hashed) UUID',
52 );
53 }
54
55 parent::__construct($fields, $numberConverter, $codec, $timeConverter);
56 }
57 }