/**
* Convert a string to snake case.
*
* @param string $value
* @param string $delimiter
* @return string
*/
function convertToSnakeCase($value, $delimiter = '_')
{
if (!ctype_lower($value)) {
$value = preg_replace('/\s+/u', '', ucwords($value));
$value = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value));
}
return $value;
}