|
1
|
|
|
<?php |
|
2
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
3
|
|
|
namespace SetBased\Audit\MySql\Helper; |
|
4
|
|
|
|
|
5
|
|
|
use SetBased\Audit\MySql\Metadata\ColumnMetadata; |
|
6
|
|
|
use SetBased\Audit\MySql\Metadata\TableColumnsMetadata; |
|
7
|
|
|
|
|
8
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
9
|
|
|
/** |
|
10
|
|
|
* Class container for all column types like audit,data and config. |
|
11
|
|
|
*/ |
|
12
|
|
|
class DiffTableColumns |
|
13
|
|
|
{ |
|
14
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
15
|
|
|
/** |
|
16
|
|
|
* Contains all column types from audit and data schemas. |
|
17
|
|
|
* |
|
18
|
|
|
* @var array[] |
|
19
|
|
|
*/ |
|
20
|
|
|
private $columnTypes = []; |
|
21
|
|
|
|
|
22
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
23
|
|
|
/** |
|
24
|
|
|
* Object constructor |
|
25
|
|
|
* |
|
26
|
|
|
* @param TableColumnsMetadata $configColumns The table columns from config file. |
|
27
|
|
|
* @param TableColumnsMetadata $auditColumns The table columns from audit schema. |
|
28
|
|
|
* @param TableColumnsMetadata $dataColumns The table columns from data schema. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct($configColumns, $auditColumns, $dataColumns) |
|
31
|
|
|
{ |
|
32
|
|
|
$auditConfigTypes = $configColumns; |
|
33
|
|
|
$auditTypes = $auditColumns; |
|
34
|
|
|
$dataTypes = $dataColumns; |
|
35
|
|
|
$allTypes = ['config' => $auditConfigTypes, 'audit' => $auditTypes, 'data' => $dataTypes]; |
|
36
|
|
|
|
|
37
|
|
|
$this->appendColumnTypes($allTypes); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
41
|
|
|
/** |
|
42
|
|
|
* Get columns types. |
|
43
|
|
|
* |
|
44
|
|
|
* @return array[] |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getTypes() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->columnTypes; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
52
|
|
|
/** |
|
53
|
|
|
* Add to array all columns types. |
|
54
|
|
|
* |
|
55
|
|
|
* @param array[] $allTypes The metadata of the column. |
|
56
|
|
|
*/ |
|
57
|
|
|
private function appendColumnTypes($allTypes) |
|
58
|
|
|
{ |
|
59
|
|
|
/** @var TableColumnsMetadata $typesArray */ |
|
60
|
|
|
foreach ($allTypes as $typePrefix => $typesArray) |
|
61
|
|
|
{ |
|
62
|
|
|
$typesArray = $typesArray->getColumns(); |
|
|
|
|
|
|
63
|
|
|
/** @var ColumnMetadata $type */ |
|
64
|
|
|
foreach ($typesArray as $type) |
|
65
|
|
|
{ |
|
66
|
|
|
if (isset($this->columnTypes[$type->getProperty('column_name')])) |
|
67
|
|
|
{ |
|
68
|
|
|
/** @var ColumnMetadataExtended */ |
|
69
|
|
|
$this->columnTypes[$type->getProperty('column_name')]->extendColumnTypes($type, $typePrefix); |
|
70
|
|
|
} |
|
71
|
|
|
else |
|
72
|
|
|
{ |
|
73
|
|
|
$this->columnTypes[$type->getProperty('column_name')] = new ColumnMetadataExtended($type, $typePrefix); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
83
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: