|
1
|
|
|
<?php |
|
2
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
3
|
|
|
namespace SetBased\Audit\MySql\Helper; |
|
4
|
|
|
|
|
5
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
6
|
|
|
/** |
|
7
|
|
|
* A helper class for DiffTable. |
|
8
|
|
|
*/ |
|
9
|
|
|
class DiffTableRowHelper |
|
10
|
|
|
{ |
|
11
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
12
|
|
|
/** |
|
13
|
|
|
* Append a row. |
|
14
|
|
|
* |
|
15
|
|
|
* @param \array[] $theExistRows Exist rows array for appending. |
|
16
|
|
|
* @param ColumnMetadataExtended $theRow Row for append. |
|
17
|
|
|
*/ |
|
18
|
|
|
public static function appendRow(&$theExistRows, $theRow) |
|
19
|
|
|
{ |
|
20
|
|
|
$theRow = $theRow->getExtendMetadata(); |
|
21
|
|
|
$theExistRows[] = self::createTableRow($theRow); |
|
22
|
|
|
if (self::checkOptions($theRow)) |
|
23
|
|
|
{ |
|
24
|
|
|
$theRow = self::createColumnOptionsRow($theRow); |
|
25
|
|
|
|
|
26
|
|
|
$theExistRows[] = $theRow; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
31
|
|
|
/** |
|
32
|
|
|
* Create table row. |
|
33
|
|
|
* |
|
34
|
|
|
* @param array[] $theRow Data for table row. |
|
35
|
|
|
* |
|
36
|
|
|
* @return array<string,null|string> |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function createColumnOptionsRow($theRow) |
|
39
|
|
|
{ |
|
40
|
|
|
$dataCharsetName = isset($theRow['data_character_set_name']) ? $theRow['data_character_set_name'] : null; |
|
41
|
|
|
$dataCollationName = isset($theRow['data_collation_name']) ? $theRow['data_collation_name'] : null; |
|
42
|
|
|
|
|
43
|
|
|
$auditCharsetName = isset($theRow['audit_character_set_name']) ? $theRow['audit_character_set_name'] : null; |
|
44
|
|
|
$auditCollationName = isset($theRow['audit_collation_name']) ? $theRow['audit_collation_name'] : null; |
|
45
|
|
|
|
|
46
|
|
|
$tableRow = ['column_name' => null, |
|
47
|
|
|
'data_table_type' => self::styledOptionsRow($dataCharsetName, $dataCollationName), |
|
48
|
|
|
'audit_table_type' => self::styledOptionsRow($auditCharsetName, $auditCollationName), |
|
49
|
|
|
'config_type' => null]; |
|
50
|
|
|
|
|
51
|
|
|
return $tableRow; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
55
|
|
|
/** |
|
56
|
|
|
* Create table row. |
|
57
|
|
|
* |
|
58
|
|
|
* @param array[] $theRow Data for table row. |
|
59
|
|
|
* |
|
60
|
|
|
* @return array<string,null|string> |
|
|
|
|
|
|
61
|
|
|
*/ |
|
62
|
|
|
public static function createTableRow($theRow) |
|
63
|
|
|
{ |
|
64
|
|
|
$tableRow = ['column_name' => isset($theRow['column_name']) ? $theRow['column_name'] : null, |
|
65
|
|
|
'data_table_type' => isset($theRow['data_column_type']) ? $theRow['data_column_type'] : null, |
|
66
|
|
|
'audit_table_type' => isset($theRow['audit_column_type']) ? $theRow['audit_column_type'] : null, |
|
67
|
|
|
'config_type' => isset($theRow['config_column_type']) ? $theRow['config_column_type'] : null]; |
|
68
|
|
|
|
|
69
|
|
|
return $tableRow; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
73
|
|
|
/** |
|
74
|
|
|
* Create table row. |
|
75
|
|
|
* |
|
76
|
|
|
* @param $theCharacterSetName |
|
77
|
|
|
* @param $theCollationName |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public static function styledOptionsRow($theCharacterSetName, $theCollationName) |
|
82
|
|
|
{ |
|
83
|
|
|
$charsetName = isset($theCharacterSetName) ? '['.$theCharacterSetName.']' : null; |
|
84
|
|
|
$collationName = isset($theCollationName) ? '['.$theCollationName.']' : null; |
|
85
|
|
|
|
|
86
|
|
|
return trim(sprintf('%s %s', $charsetName, $collationName)); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
90
|
|
|
/** |
|
91
|
|
|
* Check isset options(collation, character set name) from row. |
|
92
|
|
|
* |
|
93
|
|
|
* @param array[] $theRow Row for append. |
|
94
|
|
|
* |
|
95
|
|
|
* @return bool |
|
96
|
|
|
*/ |
|
97
|
|
|
private static function checkOptions($theRow) |
|
98
|
|
|
{ |
|
99
|
|
|
if (isset($theRow['audit_character_set_name'])) |
|
100
|
|
|
{ |
|
101
|
|
|
return true; |
|
102
|
|
|
} |
|
103
|
|
|
if (isset($theRow['data_character_set_name'])) |
|
104
|
|
|
{ |
|
105
|
|
|
return true; |
|
106
|
|
|
} |
|
107
|
|
|
if (isset($theRow['audit_collation_name'])) |
|
108
|
|
|
{ |
|
109
|
|
|
return true; |
|
110
|
|
|
} |
|
111
|
|
|
if (isset($theRow['data_collation_name'])) |
|
112
|
|
|
{ |
|
113
|
|
|
return true; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return false; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
123
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.