uploads
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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[]
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user