lithium\data\source\Database::_cast()

protected method

Cast a value according to a column type, used by Database::value().

Parameters

  • string $type

    Name of the column type.

  • string $value

    Value to cast.

  • array $column

    The column definition.

  • array $schema

    Formatted array from lithium\data\source\Database::schema().

Returns

mixed

Casted value.

Source

	protected function _cast($type, $value, $column, $schema = []) {
		$column += ['formatter' => null, 'format' => null];

		if ($value === null) {
			return 'NULL';
		}
		if (is_object($value)) {
			return $value;
		}
		if (!$formatter = $column['formatter']) {
			return $this->connection->quote($value);
		}
		if (!$format = $column['format']) {
			return $formatter($value);
		}
		if (($value = $formatter($format, $value)) === false) {
			$value = $formatter($format, $schema['default']);
		}
		return $value !== false ? $value : 'NULL';
	}