PluginProbe
Media Cloud Sync / 1.2.8
Media Cloud Sync v1.2.8
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 / Fields.php

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

106 lines 3.3 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\Ramsey\Uuid\Nonstandard;
14
15 use Dudlewebs\WPMCS\Ramsey\Uuid\Exception\InvalidArgumentException;
16 use Dudlewebs\WPMCS\Ramsey\Uuid\Fields\SerializableFieldsTrait;
17 use Dudlewebs\WPMCS\Ramsey\Uuid\Rfc4122\FieldsInterface;
18 use Dudlewebs\WPMCS\Ramsey\Uuid\Rfc4122\VariantTrait;
19 use Dudlewebs\WPMCS\Ramsey\Uuid\Type\Hexadecimal;
20 use function bin2hex;
21 use function dechex;
22 use function hexdec;
23 use function sprintf;
24 use function str_pad;
25 use function strlen;
26 use function substr;
27 use const STR_PAD_LEFT;
28 /**
29 * Nonstandard UUID fields do not conform to the RFC 4122 standard
30 *
31 * Since some systems may create nonstandard UUIDs, this implements the
32 * Rfc4122\FieldsInterface, so that functionality of a nonstandard UUID is not
33 * degraded, in the event these UUIDs are expected to contain RFC 4122 fields.
34 *
35 * Internally, this class represents the fields together as a 16-byte binary
36 * string.
37 *
38 * @psalm-immutable
39 */
40 final class Fields implements FieldsInterface
41 {
42 use SerializableFieldsTrait;
43 use VariantTrait;
44 /**
45 * @var string
46 */
47 private $bytes;
48 /**
49 * @param string $bytes A 16-byte binary string representation of a UUID
50 *
51 * @throws InvalidArgumentException if the byte string is not exactly 16 bytes
52 */
53 public function __construct(string $bytes)
54 {
55 if (strlen($bytes) !== 16) {
56 throw new InvalidArgumentException('The byte string must be 16 bytes long; ' . 'received ' . strlen($bytes) . ' bytes');
57 }
58 $this->bytes = $bytes;
59 }
60 public function getBytes(): string
61 {
62 return $this->bytes;
63 }
64 public function getClockSeq(): Hexadecimal
65 {
66 $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff;
67 return new Hexadecimal(str_pad(dechex($clockSeq), 4, '0', STR_PAD_LEFT));
68 }
69 public function getClockSeqHiAndReserved(): Hexadecimal
70 {
71 return new Hexadecimal(bin2hex(substr($this->bytes, 8, 1)));
72 }
73 public function getClockSeqLow(): Hexadecimal
74 {
75 return new Hexadecimal(bin2hex(substr($this->bytes, 9, 1)));
76 }
77 public function getNode(): Hexadecimal
78 {
79 return new Hexadecimal(bin2hex(substr($this->bytes, 10)));
80 }
81 public function getTimeHiAndVersion(): Hexadecimal
82 {
83 return new Hexadecimal(bin2hex(substr($this->bytes, 6, 2)));
84 }
85 public function getTimeLow(): Hexadecimal
86 {
87 return new Hexadecimal(bin2hex(substr($this->bytes, 0, 4)));
88 }
89 public function getTimeMid(): Hexadecimal
90 {
91 return new Hexadecimal(bin2hex(substr($this->bytes, 4, 2)));
92 }
93 public function getTimestamp(): Hexadecimal
94 {
95 return new Hexadecimal(sprintf('%03x%04s%08s', hexdec($this->getTimeHiAndVersion()->toString()) & 0xfff, $this->getTimeMid()->toString(), $this->getTimeLow()->toString()));
96 }
97 public function getVersion(): ?int
98 {
99 return null;
100 }
101 public function isNil(): bool
102 {
103 return \false;
104 }
105 }
106