1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MySQLReplication\Config; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class ConfigBuilder |
7
|
|
|
* @package MySQLReplication\Config |
8
|
|
|
*/ |
9
|
|
|
class ConfigBuilder |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private $user = ''; |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $host = 'localhost'; |
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
*/ |
22
|
|
|
private $port = 3306; |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $password = ''; |
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $charset = 'utf8'; |
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $gtid = ''; |
35
|
|
|
/** |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
private $slaveId = 666; |
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $binLogFileName = ''; |
43
|
|
|
/** |
44
|
|
|
* @var int |
45
|
|
|
*/ |
46
|
|
|
private $binLogPosition = 0; |
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
private $eventsOnly = []; |
51
|
|
|
/** |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
private $eventsIgnore = []; |
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
private $tablesOnly = []; |
59
|
|
|
/** |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
private $databasesOnly = []; |
63
|
|
|
/** |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
private $mariaDbGtid = ''; |
67
|
|
|
/** |
68
|
|
|
* @var int |
69
|
|
|
*/ |
70
|
|
|
private $tableCacheSize = 128; |
71
|
|
|
/** |
72
|
|
|
* @var array |
73
|
|
|
*/ |
74
|
|
|
private $custom = []; |
75
|
|
|
/** |
76
|
|
|
* @var int |
77
|
|
|
*/ |
78
|
|
|
private $heartbeatPeriod = 0; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $user |
82
|
|
|
* @return ConfigBuilder |
83
|
|
|
*/ |
84
|
54 |
|
public function withUser($user) |
85
|
|
|
{ |
86
|
54 |
|
$this->user = $user; |
87
|
|
|
|
88
|
54 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $host |
93
|
|
|
* @return ConfigBuilder |
94
|
|
|
*/ |
95
|
54 |
|
public function withHost($host) |
96
|
|
|
{ |
97
|
54 |
|
$this->host = $host; |
98
|
|
|
|
99
|
54 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param int $port |
104
|
|
|
* @return ConfigBuilder |
105
|
|
|
*/ |
106
|
|
|
public function withPort($port) |
107
|
|
|
{ |
108
|
|
|
$this->port = $port; |
109
|
|
|
|
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $password |
115
|
|
|
* @return ConfigBuilder |
116
|
|
|
*/ |
117
|
54 |
|
public function withPassword($password) |
118
|
|
|
{ |
119
|
54 |
|
$this->password = $password; |
120
|
|
|
|
121
|
54 |
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string $charset |
126
|
|
|
* @return ConfigBuilder |
127
|
|
|
*/ |
128
|
|
|
public function withCharset($charset) |
129
|
|
|
{ |
130
|
|
|
$this->charset = $charset; |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param string $gtid |
137
|
|
|
* @return ConfigBuilder |
138
|
|
|
*/ |
139
|
|
|
public function withGtid($gtid) |
140
|
|
|
{ |
141
|
|
|
$this->gtid = $gtid; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param int $slaveId |
148
|
|
|
* @return ConfigBuilder |
149
|
|
|
*/ |
150
|
|
|
public function withSlaveId($slaveId) |
151
|
|
|
{ |
152
|
|
|
$this->slaveId = $slaveId; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $binLogFileName |
159
|
|
|
* @return ConfigBuilder |
160
|
|
|
*/ |
161
|
|
|
public function withBinLogFileName($binLogFileName) |
162
|
|
|
{ |
163
|
|
|
$this->binLogFileName = $binLogFileName; |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param int $binLogPosition |
170
|
|
|
* @return ConfigBuilder |
171
|
|
|
*/ |
172
|
|
|
public function withBinLogPosition($binLogPosition) |
173
|
|
|
{ |
174
|
|
|
$this->binLogPosition = $binLogPosition; |
175
|
|
|
|
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @see ConstEventType |
181
|
|
|
* @param array $eventsOnly |
182
|
|
|
* @return ConfigBuilder |
183
|
|
|
*/ |
184
|
3 |
|
public function withEventsOnly(array $eventsOnly) |
185
|
|
|
{ |
186
|
3 |
|
$this->eventsOnly = $eventsOnly; |
187
|
|
|
|
188
|
3 |
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @see ConstEventType |
193
|
|
|
* @param array $eventsIgnore |
194
|
|
|
* @return ConfigBuilder |
195
|
|
|
*/ |
196
|
54 |
|
public function withEventsIgnore(array $eventsIgnore) |
197
|
|
|
{ |
198
|
54 |
|
$this->eventsIgnore = $eventsIgnore; |
199
|
|
|
|
200
|
54 |
|
return $this; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param array $tablesOnly |
205
|
|
|
* @return ConfigBuilder |
206
|
|
|
*/ |
207
|
1 |
|
public function withTablesOnly(array $tablesOnly) |
208
|
|
|
{ |
209
|
1 |
|
$this->tablesOnly = $tablesOnly; |
210
|
|
|
|
211
|
1 |
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param array $databasesOnly |
216
|
|
|
* @return ConfigBuilder |
217
|
|
|
*/ |
218
|
|
|
public function withDatabasesOnly(array $databasesOnly) |
219
|
|
|
{ |
220
|
|
|
$this->databasesOnly = $databasesOnly; |
221
|
|
|
|
222
|
|
|
return $this; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param string $mariaDbGtid |
227
|
|
|
* @return ConfigBuilder |
228
|
|
|
*/ |
229
|
|
|
public function withMariaDbGtid($mariaDbGtid) |
230
|
|
|
{ |
231
|
|
|
$this->mariaDbGtid = $mariaDbGtid; |
232
|
|
|
|
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @param int $tableCacheSize |
238
|
|
|
* @return $this |
239
|
|
|
*/ |
240
|
|
|
public function withTableCacheSize($tableCacheSize) |
241
|
|
|
{ |
242
|
|
|
$this->tableCacheSize = $tableCacheSize; |
243
|
|
|
|
244
|
|
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param array $custom |
249
|
|
|
* @return $this |
250
|
|
|
*/ |
251
|
|
|
public function withCustom(array $custom) |
252
|
|
|
{ |
253
|
|
|
$this->custom = $custom; |
254
|
|
|
|
255
|
|
|
return $this; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @see https://dev.mysql.com/doc/refman/5.6/en/change-master-to.html |
260
|
|
|
* @param int $heartbeatPeriod |
261
|
|
|
* @return $this |
262
|
|
|
*/ |
263
|
|
|
public function withHeartbeatPeriod($heartbeatPeriod) |
264
|
|
|
{ |
265
|
|
|
$this->heartbeatPeriod = $heartbeatPeriod; |
266
|
|
|
|
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @return Config |
272
|
|
|
*/ |
273
|
54 |
|
public function build() |
274
|
|
|
{ |
275
|
54 |
|
return new Config( |
276
|
54 |
|
$this->user, |
277
|
54 |
|
$this->host, |
278
|
54 |
|
$this->port, |
279
|
54 |
|
$this->password, |
280
|
54 |
|
$this->charset, |
281
|
54 |
|
$this->gtid, |
282
|
54 |
|
$this->mariaDbGtid, |
283
|
54 |
|
$this->slaveId, |
284
|
54 |
|
$this->binLogFileName, |
285
|
54 |
|
$this->binLogPosition, |
286
|
54 |
|
$this->eventsOnly, |
287
|
54 |
|
$this->eventsIgnore, |
288
|
54 |
|
$this->tablesOnly, |
289
|
54 |
|
$this->databasesOnly, |
290
|
54 |
|
$this->tableCacheSize, |
291
|
54 |
|
$this->custom, |
292
|
54 |
|
$this->heartbeatPeriod |
293
|
54 |
|
); |
294
|
|
|
} |
295
|
|
|
} |