From 4fa45083d07019cf97cf13ce2cee8a1d2d1a67c9 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Sun, 2 Nov 2025 09:50:03 +0100 Subject: [PATCH] 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 --- src/Helpers/UUID.php | 63 ++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/src/Helpers/UUID.php b/src/Helpers/UUID.php index 887f99b..8bdfe9b 100644 --- a/src/Helpers/UUID.php +++ b/src/Helpers/UUID.php @@ -2,37 +2,42 @@ namespace vlw\Scaffold\Helpers; - const UUID_LENGTH = 36; - /** - * Generate an all binary 0:s UUID - * - * @return string + * Generate Universally unique identifiers */ - function uuid_nil(): string { - return "00000000-0000-0000-0000-000000000000"; - } + class UUID { + public const LENGTH = 36; - /** - * Generate an all binary 1:s UUID - * - * @return string - */ - function uuid_max(): string { - return "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"; - } + /** + * Generate an all binary 0:s UUID + * + * @return string + */ + public static function nil(): string { + return "00000000-0000-0000-0000-000000000000"; + } - /** - * Generate a version 4 UUID - * - * @return string - */ - function uuid_v4(): string { - 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, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); + /** + * Generate an all binary 1:s UUID + * + * @return string + */ + public static function max(): string { + return "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"; + } + + /** + * Generate a version 4 UUID + * + * @return string + */ + public static function v4(): string { + 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, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) + ); + } }