<?php
/**
* Validates time configuration from a configuration file.
*
* @param array $config An array containing time configuration values.
* @return bool True if the configuration is valid, false otherwise.
*/
function validateTimeConfig(array $config): bool
{
// Check if the configuration array is empty.
if (empty($config)) {
error_log("Error: Configuration array is empty.");
return false;
}
// Validate 'debug_time_format'
if (!is_string($config['debug_time_format'])) {
error_log("Error: debug_time_format must be a string.");
return false;
}
// Validate 'debug_time_precision'
if (!is_int($config['debug_time_precision']) || $config['debug_time_precision'] < 0 || $config['debug_time_precision'] > 6) {
error_log("Error: debug_time_precision must be an integer between 0 and 6.");
return false;
}
// Validate 'debug_time_zone'
if (!is_string($config['debug_time_zone'])) {
error_log("Error: debug_time_zone must be a string.");
return false;
}
// Validate 'debug_time_enable'
if (!is_bool($config['debug_time_enable'])) {
error_log("Error: debug_time_enable must be a boolean.");
return false;
}
return true; // Configuration is valid.
}
// Example usage (for testing)
/*
$config = [
'debug_time_format' => 'Y-m-d H:i:s.u',
'debug_time_precision' => 6,
'debug_time_zone' => 'UTC',
'debug_time_enable' => true,
];
if (validateTimeConfig($config)) {
echo "Time configuration is valid.\n";
} else {
echo "Time configuration is invalid.\n";
}
*/
?>
Add your comment