1 | <?php |
||
2 | /** |
||
3 | * Plasma Driver MySQL component |
||
4 | * Copyright 2018 PlasmaPHP, All Rights Reserved |
||
5 | * |
||
6 | * Website: https://github.com/PlasmaPHP |
||
7 | * License: https://github.com/PlasmaPHP/driver-mysql/blob/master/LICENSE |
||
8 | */ |
||
9 | |||
10 | namespace Plasma\Drivers\MySQL; |
||
11 | |||
12 | /** |
||
13 | * Text protocol rowset values decoder. |
||
14 | * @internal |
||
15 | */ |
||
16 | class TextProtocolValues { |
||
17 | /** |
||
18 | * Standard decode value, if type extensions failed. |
||
19 | * @param \Plasma\ColumnDefinitionInterface $column |
||
20 | * @param string|null $param |
||
21 | * @return mixed |
||
22 | * @throws \Plasma\Exception |
||
23 | */ |
||
24 | 7 | static function decode(\Plasma\ColumnDefinitionInterface $column, $param) { |
|
25 | 7 | $type = $column->getType(); |
|
26 | 7 | $flags = $column->getFlags(); |
|
27 | |||
28 | 7 | if($param !== null && ($flags & \Plasma\Drivers\MySQL\FieldFlags::ZEROFILL_FLAG) === 0) { |
|
29 | switch(true) { |
||
30 | 7 | case ($type === 'LONG'): |
|
1 ignored issue
–
show
Coding Style
introduced
by
![]() |
|||
31 | 1 | if(($flags & \Plasma\Drivers\MySQL\FieldFlags::UNSIGNED_FLAG) === 0 || \PHP_INT_SIZE > 4) { |
|
32 | 1 | $param = (int) $param; |
|
33 | } |
||
1 ignored issue
–
show
|
|||
34 | 1 | break; |
|
1 ignored issue
–
show
|
|||
35 | 7 | case ($type === 'LONGLONG'): |
|
1 ignored issue
–
show
|
|||
36 | 1 | if(($flags & \Plasma\Drivers\MySQL\FieldFlags::UNSIGNED_FLAG) === 0 && \PHP_INT_SIZE > 4) { |
|
37 | 1 | $param = (int) $param; |
|
38 | } |
||
39 | 1 | break; |
|
1 ignored issue
–
show
|
|||
40 | 7 | case static::isTypeTinyShortInt($type): |
|
1 ignored issue
–
show
|
|||
41 | 1 | $param = (int) $param; |
|
42 | 1 | break; |
|
1 ignored issue
–
show
|
|||
43 | 6 | case static::isTypeFloat($type): |
|
1 ignored issue
–
show
|
|||
44 | 1 | $param = (float) $param; |
|
45 | 1 | break; |
|
46 | // Other types are taken as string |
||
47 | } |
||
48 | } |
||
49 | |||
50 | 7 | return $param; |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param string $type |
||
55 | * @return bool |
||
56 | */ |
||
57 | 7 | static function isTypeTinyShortInt(string $type): bool { |
|
58 | 7 | $types = array('TINY', 'SHORT', 'INT24'); |
|
59 | 7 | return \in_array($type, $types, true); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param string $type |
||
64 | * @return bool |
||
65 | */ |
||
66 | 6 | static function isTypeFloat(string $type): bool { |
|
67 | 6 | $types = array('FLOAT', 'DOUBLE'); |
|
68 | 6 | return \in_array($type, $types, true); |
|
69 | } |
||
70 | } |
||
71 |