Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathId.php
More file actions
425 lines (368 loc) · 9.48 KB
/
Copy pathId.php
File metadata and controls
425 lines (368 loc) · 9.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<?php
declare(strict_types=1);
namespace Infocyph\UID;
use DateTimeInterface;
use Exception;
use Infocyph\UID\Configuration\RandflakeConfig;
use Infocyph\UID\Configuration\SnowflakeConfig;
use Infocyph\UID\Configuration\SonyflakeConfig;
use Infocyph\UID\Configuration\TBSLConfig;
use Infocyph\UID\Enums\IdOutputType;
use Infocyph\UID\Enums\UlidGenerationMode;
use Infocyph\UID\Value\SnowflakeValue;
use Infocyph\UID\Value\SonyflakeValue;
use Infocyph\UID\Value\TbslValue;
use Infocyph\UID\Value\UlidValue;
use Infocyph\UID\Value\UuidValue;
final class Id
{
/**
* @throws Exception
*/
public static function cuid2(int $maxLength = 24): string
{
return CUID2::generate($maxLength);
}
public static function cuid2IsValid(string $id): bool
{
return CUID2::isValid($id);
}
/**
* @return array{isValid: bool, length: int}
*/
public static function cuid2Parse(string $id): array
{
return CUID2::parse($id);
}
public static function deterministic(string $payload, int $length = 24, string $namespace = 'default'): string
{
return DeterministicId::fromPayload($payload, $length, $namespace);
}
/**
* @throws Exception
*/
public static function ksuid(?DateTimeInterface $dateTime = null): string
{
return KSUID::generate($dateTime);
}
/**
* @throws Exception
*/
public static function nanoId(int $size = 21): string
{
return NanoID::generate($size);
}
public static function nanoIdIsValid(string $id, ?int $size = null): bool
{
return NanoID::isValid($id, $size);
}
/**
* @return array{isValid: bool, length: int, alphabet: string}
*/
public static function nanoIdParse(string $id, ?int $size = null): array
{
return NanoID::parse($id, $size);
}
/**
* @throws Exception
*/
public static function opaque(int $length = 12): string
{
return OpaqueId::random($length);
}
/**
* @throws Exception
*/
public static function randflake(RandflakeConfig $config): int|string
{
return Randflake::generateWithConfig($config);
}
/**
* @throws Exception
*/
public static function randflakeString(RandflakeConfig $config): string
{
$id = Randflake::generateWithConfig(
new RandflakeConfig(
nodeId: $config->nodeId,
leaseStart: $config->leaseStart,
leaseEnd: $config->leaseEnd,
secret: $config->secret,
sequenceProvider: $config->sequenceProvider,
outputType: IdOutputType::STRING,
),
);
return Randflake::encodeString((string) $id);
}
/**
* @throws Exception
*/
public static function snowflake(?SnowflakeConfig $config = null): int|string
{
if ($config === null) {
return Snowflake::generate();
}
return Snowflake::generateWithConfig($config);
}
/**
* @throws Exception
*/
public static function snowflakeValue(?SnowflakeConfig $config = null): SnowflakeValue
{
return new SnowflakeValue((string) self::snowflake($config));
}
/**
* @throws Exception
*/
public static function sonyflake(?SonyflakeConfig $config = null): int|string
{
if ($config === null) {
return Sonyflake::generate();
}
return Sonyflake::generateWithConfig($config);
}
/**
* @throws Exception
*/
public static function sonyflakeValue(?SonyflakeConfig $config = null): SonyflakeValue
{
return new SonyflakeValue((string) self::sonyflake($config));
}
/**
* @throws Exception
*/
public static function tbsl(?TBSLConfig $config = null): int|string
{
if ($config === null) {
return TBSL::generate();
}
return TBSL::generateWithConfig($config);
}
/**
* @throws Exception
*/
public static function tbslValue(?TBSLConfig $config = null): TbslValue
{
return new TbslValue((string) self::tbsl($config));
}
/**
* @throws Exception
*/
public static function ulid(
?DateTimeInterface $dateTime = null,
UlidGenerationMode $mode = UlidGenerationMode::MONOTONIC,
): string {
return ULID::generate($dateTime, $mode);
}
/**
* @throws Exception
*/
public static function ulidValue(
?DateTimeInterface $dateTime = null,
UlidGenerationMode $mode = UlidGenerationMode::MONOTONIC,
): UlidValue {
return new UlidValue(self::ulid($dateTime, $mode));
}
/**
* Default UUID strategy (v7).
*
* @throws Exception
*/
public static function uuid(?DateTimeInterface $dateTime = null, ?string $node = null): string
{
return self::uuid7($dateTime, $node);
}
/**
* @throws Exception
*/
public static function uuid1(?string $node = null): string
{
return UUID::v1($node);
}
/**
* @throws Exception
*/
public static function uuid1Value(?string $node = null): UuidValue
{
return new UuidValue(self::uuid1($node));
}
/**
* @throws Exception
*/
public static function uuid3(string $namespace, string $string): string
{
return UUID::v3($namespace, $string);
}
/**
* @throws Exception
*/
public static function uuid3Value(string $namespace, string $string): UuidValue
{
return new UuidValue(self::uuid3($namespace, $string));
}
/**
* @throws Exception
*/
public static function uuid4(): string
{
return UUID::v4();
}
/**
* @throws Exception
*/
public static function uuid4Value(): UuidValue
{
return new UuidValue(self::uuid4());
}
/**
* @throws Exception
*/
public static function uuid5(string $namespace, string $string): string
{
return UUID::v5($namespace, $string);
}
/**
* @throws Exception
*/
public static function uuid5Value(string $namespace, string $string): UuidValue
{
return new UuidValue(self::uuid5($namespace, $string));
}
/**
* @throws Exception
*/
public static function uuid6(?string $node = null): string
{
return UUID::v6($node);
}
/**
* @throws Exception
*/
public static function uuid6Value(?string $node = null): UuidValue
{
return new UuidValue(self::uuid6($node));
}
/**
* @throws Exception
*/
public static function uuid7(?DateTimeInterface $dateTime = null, ?string $node = null): string
{
return UUID::v7($dateTime, $node);
}
/**
* @throws Exception
*/
public static function uuid7Value(?DateTimeInterface $dateTime = null, ?string $node = null): UuidValue
{
return new UuidValue(self::uuid7($dateTime, $node));
}
/**
* @throws Exception
*/
public static function uuid8(?string $node = null): string
{
return UUID::v8($node);
}
/**
* @throws Exception
*/
public static function uuid8Value(?string $node = null): UuidValue
{
return new UuidValue(self::uuid8($node));
}
/**
* @throws Exception
*/
public static function uuidBraces(string $uuid): string
{
return UUID::toBraces($uuid);
}
/**
* @throws Exception
*/
public static function uuidCompact(string $uuid): string
{
return UUID::compact($uuid);
}
/**
* @throws Exception
*/
public static function uuidFromBase(string $encoded, int $base): string
{
return UUID::fromBase($encoded, $base);
}
/**
* @throws Exception
*/
public static function uuidFromBytes(string $bytes): string
{
return UUID::fromBytes($bytes);
}
public static function uuidIsMax(string $uuid): bool
{
return UUID::isMax($uuid);
}
public static function uuidIsNil(string $uuid): bool
{
return UUID::isNil($uuid);
}
public static function uuidIsValid(string $uuid): bool
{
return UUID::isValid($uuid);
}
public static function uuidMax(): string
{
return UUID::max();
}
public static function uuidNil(): string
{
return UUID::nil();
}
/**
* @throws Exception
*/
public static function uuidNormalize(string $uuid): string
{
return UUID::normalize($uuid);
}
/**
* @return array{isValid: bool, version: int|null, variant: string|null, time: \DateTimeInterface|null, node: string|null, tail: string|null}
* @throws Exception
*/
public static function uuidParse(string $uuid): array
{
return UUID::parse($uuid);
}
/**
* @throws Exception
*/
public static function uuidToBase(string $uuid, int $base): string
{
return UUID::toBase($uuid, $base);
}
/**
* @throws Exception
*/
public static function uuidToBytes(string $uuid): string
{
return UUID::toBytes($uuid);
}
/**
* @throws Exception
*/
public static function uuidUrn(string $uuid): string
{
return UUID::toUrn($uuid);
}
public static function uuidValue(string $uuid): UuidValue
{
return new UuidValue($uuid);
}
/**
* @throws Exception
*/
public static function xid(): string
{
return XID::generate();
}
}
You can’t perform that action at this time.
