1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license http://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace edgardmessias\db\firebird; |
9
|
|
|
|
10
|
|
|
use yii\db\ExpressionInterface; |
11
|
|
|
use yii\db\PdoValue; |
12
|
|
|
use yii\db\Query; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* |
16
|
|
|
* @author Edgard Lorraine Messias <[email protected]> |
17
|
|
|
* @since 2.0 |
18
|
|
|
*/ |
19
|
|
|
class ColumnSchema extends \yii\db\ColumnSchema |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Converts the input value according to [[phpType]] after retrieval from the database. |
24
|
|
|
* If the value is null or an [[Expression]], it will not be converted. |
25
|
|
|
* @param mixed $value input value |
26
|
|
|
* @return mixed converted value |
27
|
98 |
|
* @since 2.0.3 |
28
|
|
|
*/ |
29
|
|
|
protected function typecast($value) |
30
|
98 |
|
{ |
31
|
1 |
|
if ($value === '' |
32
|
|
|
&& !in_array( |
33
|
98 |
|
$this->type, |
34
|
94 |
|
[ |
35
|
|
|
Schema::TYPE_TEXT, |
36
|
|
|
Schema::TYPE_STRING, |
37
|
87 |
|
Schema::TYPE_BINARY, |
38
|
87 |
|
Schema::TYPE_CHAR |
39
|
87 |
|
], |
40
|
42 |
|
true) |
41
|
|
|
) { |
42
|
|
|
return null; |
43
|
42 |
|
} |
44
|
|
|
|
45
|
2 |
|
if ($value === null |
46
|
|
|
|| gettype($value) === $this->phpType |
47
|
42 |
|
|| $value instanceof ExpressionInterface |
48
|
63 |
|
|| $value instanceof Query |
49
|
63 |
|
) { |
50
|
3 |
|
return $value; |
51
|
|
|
} |
52
|
63 |
|
|
53
|
16 |
|
if (is_array($value) |
54
|
|
|
&& count($value) === 2 |
55
|
16 |
|
&& isset($value[1]) |
56
|
16 |
|
&& in_array($value[1], $this->getPdoParamTypes(), true) |
57
|
|
|
) { |
58
|
|
|
return new PdoValue($value[0], $value[1]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
switch ($this->phpType) { |
62
|
|
|
case 'resource': |
63
|
|
|
case 'string': |
64
|
|
|
if (is_resource($value)) { |
65
|
|
|
return $value; |
66
|
|
|
} |
67
|
|
|
if (is_float($value)) { |
68
|
|
|
// ensure type cast always has . as decimal separator in all locales |
69
|
|
|
return str_replace(',', '.', (string) $value); |
70
|
|
|
} |
71
|
|
|
return (string) $value; |
72
|
|
|
case 'integer': |
73
|
|
|
if (is_bool($value)) { |
74
|
|
|
return ($value) ? 1 : 0; |
75
|
|
|
} |
76
|
|
|
return (int) $value; |
77
|
|
|
case 'boolean': |
78
|
|
|
return (boolean) $value; |
79
|
|
|
case 'double': |
80
|
|
|
return (double) $value; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $value; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return int[] array of numbers that represent possible PDO parameter types |
88
|
|
|
*/ |
89
|
|
|
private function getPdoParamTypes() |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
return [\PDO::PARAM_BOOL, \PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB, \PDO::PARAM_NULL, \PDO::PARAM_STMT]; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.