This commit is contained in:
2026-02-03 09:18:15 +01:00
parent 13efe9406c
commit dc427490a5
42 changed files with 5104 additions and 65 deletions

View File

@@ -48,6 +48,16 @@ final class ConfigLoader
});
}
/**
* @return array<string,mixed>
*/
public function avatars(): array
{
return $this->load('avatars.json', function (array $config): void {
$this->validator->validateAvatars($config, 'avatars.json');
});
}
/**
* @param callable(array<string,mixed>):void $validate
* @return array<string,mixed>

View File

@@ -177,6 +177,33 @@ final class ConfigValidator
}
}
/**
* @param array<string,mixed> $config
*/
public function validateAvatars(array $config, string $file): void
{
$errors = [];
if (!isset($config['avatars']) || !is_array($config['avatars'])) {
$errors[] = "'avatars' muss ein Array sein";
}
if (isset($config['avatars']) && is_array($config['avatars'])) {
foreach ($config['avatars'] as $idx => $avatar) {
if (!is_array($avatar)) {
$errors[] = "Avatar #{$idx} muss ein Objekt sein";
continue;
}
foreach (['key', 'label', 'image'] as $req) {
if (empty($avatar[$req]) || !is_string($avatar[$req])) {
$errors[] = "Avatar #{$idx}: '{$req}' fehlt";
}
}
}
}
if ($errors) {
throw new ConfigValidationException($file, $errors);
}
}
/**
* @return string[]
*/