lithium\data\source\Database::value()
Converts a given value into the proper type based on a given schema definition.
Will bypass any formatters and casting - effectively forcing the engine "to keep its
hands off" - when $value
is an object with the property scalar
(created by casting
a scalar value to an object i.e. (object) 'foo')
. This feature allows to construct
values or queries that are not (yet) supported by the engine.
Parameters
-
mixed
$value
The value to be converted. Arrays will be recursively converted.
-
array
$schema
Formatted array from
lithium\data\source\Database::schema()
Returns
mixedvalue with converted type
Source
public function value($value, array $schema = []) {
$schema += ['default' => null, 'null' => false];
if (is_array($value)) {
foreach ($value as $key => $val) {
$value[$key] = $this->value($val, isset($schema[$key]) ? $schema[$key] : $schema);
}
return $value;
}
if (is_object($value) && isset($value->scalar)) {
return $value->scalar;
}
$type = isset($schema['type']) ? $schema['type'] : $this->_introspectType($value);
$column = isset($this->_columns[$type]) ? $this->_columns[$type] : null;
return $this->_cast($type, $value, $column, $schema);
}