lithium\data\source\Database::_toBoolean()
Casts a value which is being written or compared to a boolean-type database column.
Parameters
-
mixed
$value
A value of unknown type to be cast to boolean. Numeric values not equal to zero evaluate to
true
, otherwisefalse
. String values equal to'true'
,'t'
or'T'
evaluate totrue
, all others tofalse
. In all other cases, uses PHP's default casting.
Returns
booleanReturns a boolean representation of $value
, based on the comparison rules
specified above. Database adapters may override this method if boolean type coercion
is required and falls outside the rules defined.
Source
protected function _toBoolean($value) {
if (is_bool($value)) {
return $value;
}
if (is_int($value) || is_float($value)) {
return ($value !== 0);
}
if (is_string($value)) {
return ($value === 't' || $value === 'T' || $value === 'true');
}
return (boolean) $value;
}