| @@ -10,63 +10,54 @@ | ||
| 10 | 10 | * @license http://opensource.org/licenses/MIT MIT |
| 11 | 11 | * phpcs:disable Squiz.Functions.GlobalFunction |
| 12 | 12 | */ |
| 13 | 13 | declare (strict_types=1); |
| 14 | -namespace Dudlewebs\WPMCS\Ramsey\Uuid; | |
| 14 | +namespace Dudlewebs\WPMCS\GCP\Ramsey\Uuid; | |
| 15 | 15 | |
| 16 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Type\Hexadecimal; | |
| 17 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Type\Integer as IntegerObject; | |
| 16 | +use DateTimeInterface; | |
| 17 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Type\Hexadecimal; | |
| 18 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Type\Integer as IntegerObject; | |
| 18 | 19 | /** |
| 19 | - * Returns a version 1 (time-based) UUID from a host ID, sequence number, | |
| 20 | - * and the current time | |
| 20 | + * Returns a version 1 (Gregorian time) UUID from a host ID, sequence number, and the current time | |
| 21 | 21 | * |
| 22 | - * @param Hexadecimal|int|string|null $node A 48-bit number representing the | |
| 23 | - * hardware address; this number may be represented as an integer or a | |
| 24 | - * hexadecimal string | |
| 25 | - * @param int $clockSeq A 14-bit number used to help avoid duplicates that | |
| 26 | - * could arise when the clock is set backwards in time or if the node ID | |
| 27 | - * changes | |
| 22 | + * @param Hexadecimal | int | string | null $node A 48-bit number representing the hardware address; this number may be | |
| 23 | + * represented as an integer or a hexadecimal string | |
| 24 | + * @param int | null $clockSeq A 14-bit number used to help avoid duplicates that could arise when the clock is set | |
| 25 | + * backwards in time or if the node ID changes | |
| 28 | 26 | * |
| 29 | 27 | * @return non-empty-string Version 1 UUID as a string |
| 30 | 28 | */ |
| 31 | -function v1($node = null, ?int $clockSeq = null): string | |
| 29 | +function v1($node = null, ?int $clockSeq = null) : string | |
| 32 | 30 | { |
| 33 | 31 | return Uuid::uuid1($node, $clockSeq)->toString(); |
| 34 | 32 | } |
| 35 | 33 | /** |
| 36 | - * Returns a version 2 (DCE Security) UUID from a local domain, local | |
| 37 | - * identifier, host ID, clock sequence, and the current time | |
| 34 | + * Returns a version 2 (DCE Security) UUID from a local domain, local identifier, host ID, clock sequence, and the current time | |
| 38 | 35 | * |
| 39 | - * @param int $localDomain The local domain to use when generating bytes, | |
| 40 | - * according to DCE Security | |
| 41 | - * @param IntegerObject|null $localIdentifier The local identifier for the | |
| 42 | - * given domain; this may be a UID or GID on POSIX systems, if the local | |
| 43 | - * domain is person or group, or it may be a site-defined identifier | |
| 44 | - * if the local domain is org | |
| 45 | - * @param Hexadecimal|null $node A 48-bit number representing the hardware | |
| 46 | - * address | |
| 47 | - * @param int|null $clockSeq A 14-bit number used to help avoid duplicates | |
| 48 | - * that could arise when the clock is set backwards in time or if the | |
| 49 | - * node ID changes | |
| 36 | + * @param int $localDomain The local domain to use when generating bytes, according to DCE Security | |
| 37 | + * @param IntegerObject | null $localIdentifier The local identifier for the given domain; this may be a UID or GID on | |
| 38 | + * POSIX systems, if the local domain is a person or group, or it may be a site-defined identifier if the local | |
| 39 | + * domain is org | |
| 40 | + * @param Hexadecimal | null $node A 48-bit number representing the hardware address | |
| 41 | + * @param int | null $clockSeq A 14-bit number used to help avoid duplicates that could arise when the clock is set | |
| 42 | + * backwards in time or if the node ID changes | |
| 50 | 43 | * |
| 51 | 44 | * @return non-empty-string Version 2 UUID as a string |
| 52 | 45 | */ |
| 53 | -function v2(int $localDomain, ?IntegerObject $localIdentifier = null, ?Hexadecimal $node = null, ?int $clockSeq = null): string | |
| 46 | +function v2(int $localDomain, ?IntegerObject $localIdentifier = null, ?Hexadecimal $node = null, ?int $clockSeq = null) : string | |
| 54 | 47 | { |
| 55 | 48 | return Uuid::uuid2($localDomain, $localIdentifier, $node, $clockSeq)->toString(); |
| 56 | 49 | } |
| 57 | 50 | /** |
| 58 | - * Returns a version 3 (name-based) UUID based on the MD5 hash of a | |
| 59 | - * namespace ID and a name | |
| 51 | + * Returns a version 3 (name-based) UUID based on the MD5 hash of a namespace ID and a name | |
| 60 | 52 | * |
| 61 | - * @param string|UuidInterface $ns The namespace (must be a valid UUID) | |
| 53 | + * @param UuidInterface | string $ns The namespace (must be a valid UUID) | |
| 62 | 54 | * |
| 63 | 55 | * @return non-empty-string Version 3 UUID as a string |
| 64 | 56 | * |
| 65 | - * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, | |
| 66 | - * but under constant factory setups, this method operates in functionally pure manners | |
| 57 | + * @pure | |
| 67 | 58 | */ |
| 68 | -function v3($ns, string $name): string | |
| 59 | +function v3($ns, string $name) : string | |
| 69 | 60 | { |
| 70 | 61 | return Uuid::uuid3($ns, $name)->toString(); |
| 71 | 62 | } |
| 72 | 63 | /** |
| @@ -73,39 +64,64 @@ | ||
| 73 | 64 | * Returns a version 4 (random) UUID |
| 74 | 65 | * |
| 75 | 66 | * @return non-empty-string Version 4 UUID as a string |
| 76 | 67 | */ |
| 77 | -function v4(): string | |
| 68 | +function v4() : string | |
| 78 | 69 | { |
| 79 | 70 | return Uuid::uuid4()->toString(); |
| 80 | 71 | } |
| 81 | 72 | /** |
| 82 | - * Returns a version 5 (name-based) UUID based on the SHA-1 hash of a | |
| 83 | - * namespace ID and a name | |
| 73 | + * Returns a version 5 (name-based) UUID based on the SHA-1 hash of a namespace ID and a name | |
| 84 | 74 | * |
| 85 | - * @param string|UuidInterface $ns The namespace (must be a valid UUID) | |
| 75 | + * @param UuidInterface | string $ns The namespace (must be a valid UUID) | |
| 86 | 76 | * |
| 87 | 77 | * @return non-empty-string Version 5 UUID as a string |
| 88 | 78 | * |
| 89 | - * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, | |
| 90 | - * but under constant factory setups, this method operates in functionally pure manners | |
| 79 | + * @pure | |
| 91 | 80 | */ |
| 92 | -function v5($ns, string $name): string | |
| 81 | +function v5($ns, string $name) : string | |
| 93 | 82 | { |
| 94 | 83 | return Uuid::uuid5($ns, $name)->toString(); |
| 95 | 84 | } |
| 96 | 85 | /** |
| 97 | - * Returns a version 6 (ordered-time) UUID from a host ID, sequence number, | |
| 98 | - * and the current time | |
| 86 | + * Returns a version 6 (reordered Gregorian time) UUID from a host ID, sequence number, and the current time | |
| 99 | 87 | * |
| 100 | - * @param Hexadecimal|null $node A 48-bit number representing the hardware | |
| 101 | - * address | |
| 102 | - * @param int $clockSeq A 14-bit number used to help avoid duplicates that | |
| 103 | - * could arise when the clock is set backwards in time or if the node ID | |
| 104 | - * changes | |
| 88 | + * @param Hexadecimal | null $node A 48-bit number representing the hardware address | |
| 89 | + * @param int | null $clockSeq A 14-bit number used to help avoid duplicates that could arise when the clock is set | |
| 90 | + * backwards in time or if the node ID changes | |
| 105 | 91 | * |
| 106 | 92 | * @return non-empty-string Version 6 UUID as a string |
| 107 | 93 | */ |
| 108 | -function v6(?Hexadecimal $node = null, ?int $clockSeq = null): string | |
| 94 | +function v6(?Hexadecimal $node = null, ?int $clockSeq = null) : string | |
| 109 | 95 | { |
| 110 | 96 | return Uuid::uuid6($node, $clockSeq)->toString(); |
| 97 | +} | |
| 98 | +/** | |
| 99 | + * Returns a version 7 (Unix Epoch time) UUID | |
| 100 | + * | |
| 101 | + * @param DateTimeInterface|null $dateTime An optional date/time from which to create the version 7 UUID. If not | |
| 102 | + * provided, the UUID is generated using the current date/time. | |
| 103 | + * | |
| 104 | + * @return non-empty-string Version 7 UUID as a string | |
| 105 | + */ | |
| 106 | +function v7(?DateTimeInterface $dateTime = null) : string | |
| 107 | +{ | |
| 108 | + return Uuid::uuid7($dateTime)->toString(); | |
| 109 | +} | |
| 110 | +/** | |
| 111 | + * Returns a version 8 (custom format) UUID | |
| 112 | + * | |
| 113 | + * The bytes provided may contain any value according to your application's needs. Be aware, however, that other | |
| 114 | + * applications may not understand the semantics of the value. | |
| 115 | + * | |
| 116 | + * @param string $bytes A 16-byte octet string. This is an open blob of data that you may fill with 128 bits of | |
| 117 | + * information. Be aware, however, bits 48 through 51 will be replaced with the UUID version field, and bits 64 and | |
| 118 | + * 65 will be replaced with the UUID variant. You MUST NOT rely on these bits for your application needs. | |
| 119 | + * | |
| 120 | + * @return non-empty-string Version 8 UUID as a string | |
| 121 | + * | |
| 122 | + * @pure | |
| 123 | + */ | |
| 124 | +function v8(string $bytes) : string | |
| 125 | +{ | |
| 126 | + return Uuid::uuid8($bytes)->toString(); | |
| 111 | 127 | } |