PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.21
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.21
1.10.25 1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 All 169 releases
woocommerce-pos / vendor / ramsey / uuid / src / Nonstandard / Fields.php

Fields.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.21, at vendor/ramsey/uuid/src/Nonstandard/Fields.php

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