PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / ramsey / uuid / src / Nonstandard / UuidV6.php

UuidV6.php in Media Cloud Sync 1.4.2, at includes/sdk/google/ramsey/uuid/src/Nonstandard/UuidV6.php

79 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 declare (strict_types=1);
13 namespace Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Nonstandard;
14
15 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Codec\CodecInterface;
16 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\NumberConverterInterface;
17 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\TimeConverterInterface;
18 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Exception\InvalidArgumentException;
19 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Lazy\LazyUuidFromString;
20 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
21 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\TimeTrait;
22 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\UuidInterface;
23 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\UuidV1;
24 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Uuid as BaseUuid;
25 /**
26 * Reordered time, or version 6, UUIDs include timestamp, clock sequence, and node values that are combined into a
27 * 128-bit unsigned integer
28 *
29 * @deprecated Use {@see \Ramsey\Uuid\Rfc4122\UuidV6} instead.
30 *
31 * @link https://github.com/uuid6/uuid6-ietf-draft UUID version 6 IETF draft
32 * @link http://gh.peabody.io/uuidv6/ "Version 6" UUIDs
33 * @link https://www.rfc-editor.org/rfc/rfc9562#section-5.6 RFC 9562, 5.6. UUID Version 6
34 *
35 * @immutable
36 */
37 class UuidV6 extends BaseUuid implements UuidInterface
38 {
39 use TimeTrait;
40 /**
41 * Creates a version 6 (reordered Gregorian time) UUID
42 *
43 * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID
44 * @param NumberConverterInterface $numberConverter The number converter to use for converting hex values to/from integers
45 * @param CodecInterface $codec The codec to use when encoding or decoding UUID strings
46 * @param TimeConverterInterface $timeConverter The time converter to use for converting timestamps extracted from a
47 * UUID to unix timestamps
48 */
49 public function __construct(Rfc4122FieldsInterface $fields, NumberConverterInterface $numberConverter, CodecInterface $codec, TimeConverterInterface $timeConverter)
50 {
51 if ($fields->getVersion() !== BaseUuid::UUID_TYPE_REORDERED_TIME) {
52 throw new InvalidArgumentException('Fields used to create a UuidV6 must represent a version 6 (reordered time) UUID');
53 }
54 parent::__construct($fields, $numberConverter, $codec, $timeConverter);
55 }
56 /**
57 * Converts this UUID into an instance of a version 1 UUID
58 */
59 public function toUuidV1() : UuidV1
60 {
61 $hex = $this->getHex()->toString();
62 $hex = \substr($hex, 7, 5) . \substr($hex, 13, 3) . \substr($hex, 3, 4) . '1' . \substr($hex, 0, 3) . \substr($hex, 16);
63 /** @var LazyUuidFromString $uuid */
64 $uuid = BaseUuid::fromBytes((string) \hex2bin($hex));
65 return $uuid->toUuidV1();
66 }
67 /**
68 * Converts a version 1 UUID into an instance of a version 6 UUID
69 */
70 public static function fromUuidV1(UuidV1 $uuidV1) : \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\UuidV6
71 {
72 $hex = $uuidV1->getHex()->toString();
73 $hex = \substr($hex, 13, 3) . \substr($hex, 8, 4) . \substr($hex, 0, 5) . '6' . \substr($hex, 5, 3) . \substr($hex, 16);
74 /** @var LazyUuidFromString $uuid */
75 $uuid = BaseUuid::fromBytes((string) \hex2bin($hex));
76 return $uuid->toUuidV6();
77 }
78 }
79