protected function typecast($value)
{
if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY && $this->type !== Schema::TYPE_CHAR) {
return null;
}
if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
return $value;
}
switch ($this->phpType) {
case 'resource':
case 'string':
if (is_resource($value)) {
return $value;
}
if (is_float($value)) {
// ensure type cast always has . as decimal separator in all locales
return str_replace(',', '.', (string) $value);
}
return (string) $value;
case 'integer':
return (int) $value;
case 'boolean':
// treating a 0 bit value as false too
// https://github.com/yiisoft/yii2/issues/9006
return (bool) $value && $value !== "";
case 'double':
return (double) $value;
}
return $value;
}