diff options
Diffstat (limited to 'library/Director/Data/Db/DbDataFormatter.php')
-rw-r--r-- | library/Director/Data/Db/DbDataFormatter.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/library/Director/Data/Db/DbDataFormatter.php b/library/Director/Data/Db/DbDataFormatter.php new file mode 100644 index 0000000..d6e4eeb --- /dev/null +++ b/library/Director/Data/Db/DbDataFormatter.php @@ -0,0 +1,26 @@ +<?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) + )); + } +} |