You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
622 B
PHP

<?php
/**
* Convert environment variable strings to boolean values
*/
$env_to_bool = function ($v): bool {
if (is_bool($v)) {
return $v;
}
if (is_numeric($v)) {
return (bool) intval($v);
}
if (is_string($v)) {
$n = mb_strtolower(trim($v));
if (in_array($n, ['1', 'true', 'on', 'yes', 'y', 't'], true)) {
return true;
}
if (in_array($n, ['0', 'false', 'off', 'no', 'n', 'f', ''], true)) {
return false;
}
}
throw new Exception('Could not convert value to bool: ' . var_export($v, true));
};
return $env_to_bool;