1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MySQLReplication\Event; |
4
|
|
|
|
5
|
|
|
use MySQLReplication\BinLog\BinLogCurrent; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class EventInfo |
9
|
|
|
* @package MySQLReplication\BinLog |
10
|
|
|
*/ |
11
|
|
|
class EventInfo implements \JsonSerializable |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var int |
15
|
|
|
*/ |
16
|
|
|
private $timestamp; |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $type; |
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
private $id; |
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
private $size; |
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
private $pos; |
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $flag; |
37
|
|
|
/** |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
private $checkSum; |
41
|
|
|
/** |
42
|
|
|
* @var int |
43
|
|
|
*/ |
44
|
|
|
private $sizeNoHeader; |
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $dateTime; |
49
|
|
|
/** |
50
|
|
|
* @var BinLogCurrent |
51
|
|
|
*/ |
52
|
|
|
private $binLogCurrent; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* EventInfo constructor. |
56
|
|
|
* @param int $timestamp |
57
|
|
|
* @param string $type |
58
|
|
|
* @param int $id |
59
|
|
|
* @param int $size |
60
|
|
|
* @param int $pos |
61
|
|
|
* @param string $flag |
62
|
|
|
* @param bool $checkSum |
63
|
|
|
* @param BinLogCurrent $binLogCurrent |
64
|
|
|
*/ |
65
|
54 |
|
public function __construct( |
66
|
|
|
$timestamp, |
67
|
|
|
$type, |
68
|
|
|
$id, |
69
|
|
|
$size, |
70
|
|
|
$pos, |
71
|
|
|
$flag, |
72
|
|
|
$checkSum, |
73
|
|
|
BinLogCurrent $binLogCurrent |
74
|
|
|
) { |
75
|
54 |
|
$this->timestamp = $timestamp; |
76
|
54 |
|
$this->type = $type; |
77
|
54 |
|
$this->id = $id; |
78
|
54 |
|
$this->size = $size; |
79
|
54 |
|
$this->pos = $pos; |
80
|
54 |
|
$this->flag = $flag; |
81
|
54 |
|
$this->checkSum = $checkSum; |
82
|
54 |
|
$this->binLogCurrent = $binLogCurrent; |
83
|
|
|
|
84
|
54 |
|
if ($pos > 0) { |
85
|
54 |
|
$this->binLogCurrent->setBinLogPosition($pos); |
86
|
54 |
|
} |
87
|
54 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return BinLogCurrent |
91
|
|
|
*/ |
92
|
|
|
public function getBinLogCurrent() |
93
|
|
|
{ |
94
|
|
|
return $this->binLogCurrent; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getDateTime() |
101
|
|
|
{ |
102
|
|
|
if (empty($this->dateTime)) { |
103
|
|
|
$this->dateTime = date('c', $this->timestamp); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->dateTime; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
54 |
|
public function getSizeNoHeader() |
113
|
|
|
{ |
114
|
54 |
|
if (empty($this->sizeNoHeader)) { |
115
|
54 |
|
$this->sizeNoHeader = (true === $this->checkSum ? $this->size - 23 : $this->size - 19); |
116
|
54 |
|
} |
117
|
|
|
|
118
|
54 |
|
return $this->sizeNoHeader; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return int |
123
|
|
|
*/ |
124
|
|
|
public function getTimestamp() |
125
|
|
|
{ |
126
|
|
|
return $this->timestamp; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
54 |
|
public function getType() |
133
|
|
|
{ |
134
|
54 |
|
return $this->type; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return int |
139
|
|
|
*/ |
140
|
|
|
public function getId() |
141
|
|
|
{ |
142
|
|
|
return $this->id; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return int |
147
|
|
|
*/ |
148
|
|
|
public function getSize() |
149
|
|
|
{ |
150
|
|
|
return $this->size; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return int |
155
|
|
|
*/ |
156
|
|
|
public function getPos() |
157
|
|
|
{ |
158
|
|
|
return $this->pos; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
public function getFlag() |
165
|
|
|
{ |
166
|
|
|
return $this->flag; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Specify data which should be serialized to JSON |
171
|
|
|
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
172
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
173
|
|
|
* which is a value of any type other than a resource. |
174
|
|
|
* @since 5.4.0 |
175
|
|
|
*/ |
176
|
|
|
public function jsonSerialize() |
177
|
|
|
{ |
178
|
|
|
return get_object_vars($this); |
179
|
|
|
} |
180
|
|
|
} |