1 | <?php |
||
17 | class DBField { |
||
18 | /** |
||
19 | * Name of the field. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | public $name; |
||
24 | |||
25 | /** |
||
26 | * Value of the field. |
||
27 | * |
||
28 | * @var mixed |
||
29 | */ |
||
30 | public $value; |
||
31 | |||
32 | /** |
||
33 | * Type of the field. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | public $type; |
||
38 | |||
39 | /** |
||
40 | * Constructor of the class with parameters validation. |
||
41 | * |
||
42 | * @param string $type Type of the field. |
||
43 | * @param string $name Name of the field. |
||
44 | * @param mixed $value Value of the field. |
||
45 | */ |
||
46 | public function __construct($type = "", $name = "", $value = null) { |
||
82 | |||
83 | /** |
||
84 | * Returns SQL type equivalent ("idsb") for common used types. |
||
85 | * |
||
86 | * @param string $fieldType Type of the field (example: "integer", "int", |
||
87 | * "double", "real", "bool", ...). |
||
88 | * |
||
89 | * @return string |
||
90 | * @throws DBFieldTypeException If invalid field type passed. |
||
91 | */ |
||
92 | public static function castType($fieldType) { |
||
114 | |||
115 | /** |
||
116 | * Returns type of the parameter by value. |
||
117 | * |
||
118 | * @param mixed $fieldValue |
||
119 | * |
||
120 | * @return string Types of the parameter ("idsb"). |
||
121 | * @throws DBFieldTypeException If can't detect field type by value. |
||
122 | */ |
||
123 | public static function getType($fieldValue) { |
||
140 | |||
141 | /** |
||
142 | * Casts field value to it's type. |
||
143 | * |
||
144 | * @param string $type Field type. |
||
145 | * @param mixed $value Field value. |
||
146 | * |
||
147 | * @return mixed Casted field value. |
||
148 | * @throws DBFieldTypeException If invalid field type provided. |
||
149 | */ |
||
150 | public static function castValue($type, $value) { |
||
164 | |||
165 | /** |
||
166 | * Returns field value in the SQL query format. |
||
167 | * |
||
168 | * @param string $type Field type. |
||
169 | * @param mixed $value Field value. |
||
170 | * |
||
171 | * @return mixed SQL formatted value of the field. |
||
172 | * @throws DBFieldTypeException If invalid field type provided. |
||
173 | */ |
||
174 | public static function sqlValue($type, $value) { |
||
201 | |||
202 | } |
||
203 | |||
209 |