Debian Codegraph @

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