public static function parseBoolean($value, $nullable = true)
{
if ($nullable && (null === $value || 'null' === $value)) {
return null;
}
if (is_bool($value)) {
return $value;
}
if (is_string($value) || is_int($value)) {
switch ((string) $value) {
case '':
case 'false':
case '0':
case 'no':
case 'off':
return false;
case 'true':
case '1':
case 'yes':
case 'on':
return true;
}
}
throw new InvalidValueException(sprintf('The value "%s" cannot be parsed as boolean.', $value));
}