lithium\data\source\Database::_formatters()
Provide an associative array of Closures to be used as the 'formatter'
key inside of the
Database::$_columns
specification. Each Closure should return the appropriately quoted
or unquoted value and accept one or two parameters: $format
, the format to apply to value
and $value
, the value to be formatted.
Example formatter function:
function($format, $value) {
return is_numeric($value) ? (integer) $value : false;
}
Returns
arrayof column types to Closure formatter
Source
protected function _formatters() {
$datetime = $timestamp = $date = $time = function($format, $value) {
if ($format && (($time = strtotime($value)) !== false)) {
$value = date($format, $time);
} else {
return false;
}
return $this->connection->quote($value);
};
return compact('datetime', 'timestamp', 'date', 'time') + [
'boolean' => function($value) {
return $value ? 1 : 0;
}
];
}