PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.8.1
Defender Security – Malware Scanner, Login Security & Firewall v5.8.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / ramsey / uuid / src / DeprecatedUuidMethodsTrait.php

DeprecatedUuidMethodsTrait.php in Defender Security – Malware Scanner, Login Security & Firewall 5.8.1, at vendor/ramsey/uuid/src/DeprecatedUuidMethodsTrait.php

327 lines 13.0 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;
16
17 use DateTimeImmutable;
18 use DateTimeInterface;
19 use Ramsey\Uuid\Converter\NumberConverterInterface;
20 use Ramsey\Uuid\Exception\DateTimeException;
21 use Ramsey\Uuid\Exception\UnsupportedOperationException;
22 use Throwable;
23
24 use function str_pad;
25 use function substr;
26
27 use const STR_PAD_LEFT;
28
29 /**
30 * This trait encapsulates deprecated methods for ramsey/uuid; this trait and its methods will be removed in ramsey/uuid 5.0.0.
31 *
32 * @deprecated This trait and its methods will be removed in ramsey/uuid 5.0.0.
33 *
34 * @immutable
35 */
36 trait DeprecatedUuidMethodsTrait
37 {
38 /**
39 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
40 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
41 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqHiAndReserved()} and use the arbitrary-precision math
42 * library of your choice to convert it to a string integer.
43 */
44 public function getClockSeqHiAndReserved(): string
45 {
46 return $this->numberConverter->fromHex($this->fields->getClockSeqHiAndReserved()->toString());
47 }
48
49 /**
50 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
51 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
52 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqHiAndReserved()}.
53 */
54 public function getClockSeqHiAndReservedHex(): string
55 {
56 return $this->fields->getClockSeqHiAndReserved()->toString();
57 }
58
59 /**
60 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
61 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
62 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqLow()} and use the arbitrary-precision math library of
63 * your choice to convert it to a string integer.
64 */
65 public function getClockSeqLow(): string
66 {
67 return $this->numberConverter->fromHex($this->fields->getClockSeqLow()->toString());
68 }
69
70 /**
71 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
72 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
73 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqLow()}.
74 */
75 public function getClockSeqLowHex(): string
76 {
77 return $this->fields->getClockSeqLow()->toString();
78 }
79
80 /**
81 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
82 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
83 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeq()} and use the arbitrary-precision math library of
84 * your choice to convert it to a string integer.
85 */
86 public function getClockSequence(): string
87 {
88 return $this->numberConverter->fromHex($this->fields->getClockSeq()->toString());
89 }
90
91 /**
92 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
93 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
94 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeq()}.
95 */
96 public function getClockSequenceHex(): string
97 {
98 return $this->fields->getClockSeq()->toString();
99 }
100
101 /**
102 * @deprecated This method will be removed in 5.0.0. There is no alternative recommendation, so plan accordingly.
103 */
104 public function getNumberConverter(): NumberConverterInterface
105 {
106 return $this->numberConverter;
107 }
108
109 /**
110 * @deprecated In ramsey/uuid version 5.0.0, this will be removed. It is available at {@see UuidV1::getDateTime()}.
111 *
112 * @return DateTimeImmutable An immutable instance of DateTimeInterface
113 *
114 * @throws UnsupportedOperationException if UUID is not time-based
115 * @throws DateTimeException if DateTime throws an exception/error
116 */
117 public function getDateTime(): DateTimeInterface
118 {
119 if ($this->fields->getVersion() !== 1) {
120 throw new UnsupportedOperationException('Not a time-based UUID');
121 }
122
123 $time = $this->timeConverter->convertTime($this->fields->getTimestamp());
124
125 try {
126 return new DateTimeImmutable(
127 '@'
128 . $time->getSeconds()->toString()
129 . '.'
130 . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT)
131 );
132 } catch (Throwable $e) {
133 throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);
134 }
135 }
136
137 /**
138 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
139 *
140 * @return string[]
141 */
142 public function getFieldsHex(): array
143 {
144 return [
145 'time_low' => $this->fields->getTimeLow()->toString(),
146 'time_mid' => $this->fields->getTimeMid()->toString(),
147 'time_hi_and_version' => $this->fields->getTimeHiAndVersion()->toString(),
148 'clock_seq_hi_and_reserved' => $this->fields->getClockSeqHiAndReserved()->toString(),
149 'clock_seq_low' => $this->fields->getClockSeqLow()->toString(),
150 'node' => $this->fields->getNode()->toString(),
151 ];
152 }
153
154 /**
155 * @deprecated This method will be removed in 5.0.0. There is no direct alternative, but the same information may be
156 * obtained by splitting in half the value returned by {@see UuidInterface::getHex()}.
157 */
158 public function getLeastSignificantBits(): string
159 {
160 $leastSignificantHex = substr($this->getHex()->toString(), 16);
161
162 return $this->numberConverter->fromHex($leastSignificantHex);
163 }
164
165 /**
166 * @deprecated This method will be removed in 5.0.0. There is no direct alternative, but the same information may be
167 * obtained by splitting in half the value returned by {@see UuidInterface::getHex()}.
168 */
169 public function getLeastSignificantBitsHex(): string
170 {
171 return substr($this->getHex()->toString(), 16);
172 }
173
174 /**
175 * @deprecated This method will be removed in 5.0.0. There is no direct alternative, but the same information may be
176 * obtained by splitting in half the value returned by {@see UuidInterface::getHex()}.
177 */
178 public function getMostSignificantBits(): string
179 {
180 $mostSignificantHex = substr($this->getHex()->toString(), 0, 16);
181
182 return $this->numberConverter->fromHex($mostSignificantHex);
183 }
184
185 /**
186 * @deprecated This method will be removed in 5.0.0. There is no direct alternative, but the same information may be
187 * obtained by splitting in half the value returned by {@see UuidInterface::getHex()}.
188 */
189 public function getMostSignificantBitsHex(): string
190 {
191 return substr($this->getHex()->toString(), 0, 16);
192 }
193
194 /**
195 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
196 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
197 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getNode()} and use the arbitrary-precision math library of your
198 * choice to convert it to a string integer.
199 */
200 public function getNode(): string
201 {
202 return $this->numberConverter->fromHex($this->fields->getNode()->toString());
203 }
204
205 /**
206 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
207 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
208 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getNode()}.
209 */
210 public function getNodeHex(): string
211 {
212 return $this->fields->getNode()->toString();
213 }
214
215 /**
216 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
217 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
218 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeHiAndVersion()} and use the arbitrary-precision math
219 * library of your choice to convert it to a string integer.
220 */
221 public function getTimeHiAndVersion(): string
222 {
223 return $this->numberConverter->fromHex($this->fields->getTimeHiAndVersion()->toString());
224 }
225
226 /**
227 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
228 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
229 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeHiAndVersion()}.
230 */
231 public function getTimeHiAndVersionHex(): string
232 {
233 return $this->fields->getTimeHiAndVersion()->toString();
234 }
235
236 /**
237 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
238 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
239 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeLow()} and use the arbitrary-precision math library of
240 * your choice to convert it to a string integer.
241 */
242 public function getTimeLow(): string
243 {
244 return $this->numberConverter->fromHex($this->fields->getTimeLow()->toString());
245 }
246
247 /**
248 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
249 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
250 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeLow()}.
251 */
252 public function getTimeLowHex(): string
253 {
254 return $this->fields->getTimeLow()->toString();
255 }
256
257 /**
258 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
259 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
260 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeMid()} and use the arbitrary-precision math library of
261 * your choice to convert it to a string integer.
262 */
263 public function getTimeMid(): string
264 {
265 return $this->numberConverter->fromHex($this->fields->getTimeMid()->toString());
266 }
267
268 /**
269 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
270 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
271 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimeMid()}.
272 */
273 public function getTimeMidHex(): string
274 {
275 return $this->fields->getTimeMid()->toString();
276 }
277
278 /**
279 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
280 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
281 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimestamp()} and use the arbitrary-precision math library of
282 * your choice to convert it to a string integer.
283 */
284 public function getTimestamp(): string
285 {
286 if ($this->fields->getVersion() !== 1) {
287 throw new UnsupportedOperationException('Not a time-based UUID');
288 }
289
290 return $this->numberConverter->fromHex($this->fields->getTimestamp()->toString());
291 }
292
293 /**
294 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
295 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
296 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getTimestamp()}.
297 */
298 public function getTimestampHex(): string
299 {
300 if ($this->fields->getVersion() !== 1) {
301 throw new UnsupportedOperationException('Not a time-based UUID');
302 }
303
304 return $this->fields->getTimestamp()->toString();
305 }
306
307 /**
308 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
309 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
310 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVariant()}.
311 */
312 public function getVariant(): ?int
313 {
314 return $this->fields->getVariant();
315 }
316
317 /**
318 * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \Ramsey\Uuid\Fields\FieldsInterface} instance.
319 * If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call
320 * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVersion()}.
321 */
322 public function getVersion(): ?int
323 {
324 return $this->fields->getVersion();
325 }
326 }
327