misuzu/src/Config/CfgTools.php

33 lines
896 B
PHP
Raw Normal View History

2023-01-01 20:23:53 +00:00
<?php
namespace Misuzu\Config;
final class CfgTools {
public static function type($value): string {
return gettype($value);
}
public static function isValidType(string $type): bool {
return $type === IConfig::T_ARR
|| $type === IConfig::T_BOOL
|| $type === IConfig::T_INT
|| $type === IConfig::T_STR;
2023-01-01 20:23:53 +00:00
}
public static function validateName(string $name): bool {
// this should better validate the format, this allows for a lot of shittery
return preg_match('#^([a-z][a-zA-Z0-9._]+)$#', $name) === 1;
}
private const DEFAULTS = [
IConfig::T_ANY => null,
IConfig::T_STR => '',
IConfig::T_INT => 0,
IConfig::T_BOOL => false,
IConfig::T_ARR => [],
2023-01-01 20:23:53 +00:00
];
public static function default(string $type) {
return self::DEFAULTS[$type] ?? null;
}
}