From 03713164fa827e7b222a4ce8e933656496f11e5b Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Mon, 20 Sep 2021 12:54:57 +0200 Subject: [PATCH] Added ID manager --- src/IdManager.php | 19 +++++++++++++++++++ tests/IdManagerTest.php | 24 +++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/IdManager.php b/src/IdManager.php index 2aed210..c860e38 100644 --- a/src/IdManager.php +++ b/src/IdManager.php @@ -4,5 +4,24 @@ namespace MMK2410\MyTodoList; class IdManager { + private static array $ids = array(); + public static function generateID(string $classname): int + { + if (!array_key_exists($classname, self::$ids)) { + self::$ids[$classname] = 0; + return 0; + } else { + return ++self::$ids[$classname]; + } + } + + public static function getCurrentId(string $classname) + { + if (!array_key_exists($classname, self::$ids)) { + return 0; + } else { + return self::$ids[$classname]; + } + } } \ No newline at end of file diff --git a/tests/IdManagerTest.php b/tests/IdManagerTest.php index 5b75021..fae830d 100644 --- a/tests/IdManagerTest.php +++ b/tests/IdManagerTest.php @@ -1,4 +1,4 @@ -