aboutsummaryrefslogtreecommitdiff
path: root/lib/classes
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2026-01-26 08:58:07 +0100
committerThomas Hackl <hackl@data-quest.de>2026-01-26 14:45:36 +0100
commitc709033cf0904827c939ec1b9b0447fea5efe0be (patch)
tree733a4b0d75e3bc9821dc463e86d4e27c6ab430c8 /lib/classes
parent28d40af3e276391d8b3456b530fea5fc7877cdb9 (diff)
make RangeConfig always return typed classes, fixes #6191
Closes #6191 Merge request studip/studip!4689
Diffstat (limited to 'lib/classes')
-rw-r--r--lib/classes/RangeConfig.class.php37
1 files changed, 31 insertions, 6 deletions
diff --git a/lib/classes/RangeConfig.class.php b/lib/classes/RangeConfig.class.php
index b1030e3..52d3ac0 100644
--- a/lib/classes/RangeConfig.class.php
+++ b/lib/classes/RangeConfig.class.php
@@ -15,8 +15,15 @@
* @category Stud.IP
*/
-class RangeConfig extends Config
+abstract class RangeConfig extends Config
{
+ private static array $range_mapping = [
+ 'sem' => CourseConfig::class,
+ 'user' => UserConfig::class,
+ 'fak' => InstituteConfig::class,
+ 'inst' => InstituteConfig::class,
+ ];
+
/**
* range type
*/
@@ -24,9 +31,9 @@ class RangeConfig extends Config
/**
* cache of created RangeConfig instances
- * @var array
+ * @var array<string, static>
*/
- protected static $instances = [];
+ private static array $instances = [];
/**
* range_id
@@ -52,10 +59,28 @@ class RangeConfig extends Config
$range_id = $range_id->getRangeId();
}
- if (!isset(static::$instances[$range_id])) {
- static::$instances[$range_id] = new static($range_id);
+ $type = get_object_type($range_id, array_keys(self::$range_mapping));
+ if (self::class === static::class) {
+ // Detect correct class for range
+ if (!$type) {
+ throw new InvalidArgumentException('Invalid range_id given');
+ }
+
+ $class_name = self::$range_mapping[$type];
+ } else {
+ // Prevent type mismatches (allow non existing ids)
+ if (
+ $type
+ && !in_array($type, array_keys(self::$range_mapping, static::class))
+ ) {
+ throw new InvalidArgumentException('Invalid range_id given');
+ }
+
+ $class_name = static::class;
}
- return static::$instances[$range_id];
+
+ return self::$instances[$range_id]
+ ??= new $class_name($range_id);
}
/**