mirror of
https://codeberg.org/vlw/scaffold.git
synced 2025-11-04 21:52:41 +01:00
feat: expose UUID helper as a class of static methods (#10)
Let's expose the uuid helpers as a class of static methods instead. I'm not sure if this approach is actually better but we're going to live with it for a while. I have done UUID helpers before this library as a class. So let's run with it again. Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/10
This commit is contained in:
parent
00337cd3aa
commit
4fa45083d0
1 changed files with 34 additions and 29 deletions
|
|
@ -2,14 +2,18 @@
|
||||||
|
|
||||||
namespace vlw\Scaffold\Helpers;
|
namespace vlw\Scaffold\Helpers;
|
||||||
|
|
||||||
const UUID_LENGTH = 36;
|
/**
|
||||||
|
* Generate Universally unique identifiers
|
||||||
|
*/
|
||||||
|
class UUID {
|
||||||
|
public const LENGTH = 36;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an all binary 0:s UUID
|
* Generate an all binary 0:s UUID
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function uuid_nil(): string {
|
public static function nil(): string {
|
||||||
return "00000000-0000-0000-0000-000000000000";
|
return "00000000-0000-0000-0000-000000000000";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -18,7 +22,7 @@
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function uuid_max(): string {
|
public static function max(): string {
|
||||||
return "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
|
return "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,7 +31,7 @@
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function uuid_v4(): string {
|
public static function v4(): string {
|
||||||
return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
|
return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
|
||||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||||
mt_rand(0, 0xffff),
|
mt_rand(0, 0xffff),
|
||||||
|
|
@ -36,3 +40,4 @@
|
||||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue