Thomas Gelf 2cff396fe4 DbDataFormatter: new helper class
Trying to reduce logic in IcingaObject
2021-05-20 16:21:46 +02:00

27 lines
627 B
PHP

<?php
namespace Icinga\Module\Director\Data\Db;
use InvalidArgumentException;
class DbDataFormatter
{
public static function normalizeBoolean($value)
{
if ($value === 'y' || $value === '1' || $value === true || $value === 1) {
return 'y';
}
if ($value === 'n' || $value === '0' || $value === false || $value === 0) {
return 'n';
}
if ($value === '' || $value === null) {
return null;
}
throw new InvalidArgumentException(sprintf(
'Got invalid boolean: %s',
var_export($value, 1)
));
}
}