forked from edgardmessias/yii2-firebird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColumnSchema.php
60 lines (53 loc) · 1.72 KB
/
ColumnSchema.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace edgardmessias\db\firebird;
/**
*
* @author Edgard Lorraine Messias <edgardmessias@gmail.com>
* @since 2.0
*/
class ColumnSchema extends \yii\db\ColumnSchema
{
/**
* Converts the input value according to [[phpType]] after retrieval from the database.
* If the value is null or an [[Expression]], it will not be converted.
* @param mixed $value input value
* @return mixed converted value
* @since 2.0.3
*/
protected function typecast($value)
{
if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) {
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':
if (is_bool($value)) {
return ($value) ? 1 : 0;
}
return (int) $value;
case 'boolean':
return (boolean) $value;
case 'double':
return (double) $value;
}
return $value;
}
}