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 $dbName = ''; |
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $charset = 'utf8'; |
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $gtid = ''; |
39
|
|
|
/** |
40
|
|
|
* @var int |
41
|
|
|
*/ |
42
|
|
|
private $slaveId = 666; |
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
private $binLogFileName = ''; |
47
|
|
|
/** |
48
|
|
|
* @var int |
49
|
|
|
*/ |
50
|
|
|
private $binLogPosition = 0; |
51
|
|
|
/** |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
private $eventsOnly = []; |
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
private $eventsIgnore = []; |
59
|
|
|
/** |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
private $tablesOnly = []; |
63
|
|
|
/** |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
private $databasesOnly = []; |
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
private $mariaDbGtid; |
71
|
|
|
/** |
72
|
|
|
* @var int |
73
|
|
|
*/ |
74
|
|
|
private $tableCacheSize = 128; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $user |
78
|
|
|
* @return ConfigBuilder |
79
|
|
|
*/ |
80
|
|
|
public function withUser($user) |
81
|
|
|
{ |
82
|
|
|
$this->user = $user; |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $host |
89
|
|
|
* @return ConfigBuilder |
90
|
|
|
*/ |
91
|
|
|
public function withHost($host) |
92
|
|
|
{ |
93
|
|
|
$this->host = $host; |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param int $port |
100
|
|
|
* @return ConfigBuilder |
101
|
|
|
*/ |
102
|
|
|
public function withPort($port) |
103
|
|
|
{ |
104
|
|
|
$this->port = $port; |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param string $password |
111
|
|
|
* @return ConfigBuilder |
112
|
|
|
*/ |
113
|
|
|
public function withPassword($password) |
114
|
|
|
{ |
115
|
|
|
$this->password = $password; |
116
|
|
|
|
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param string $dbName |
122
|
|
|
* @return ConfigBuilder |
123
|
|
|
*/ |
124
|
|
|
public function withDbName($dbName) |
125
|
|
|
{ |
126
|
|
|
$this->dbName = $dbName; |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $charset |
133
|
|
|
* @return ConfigBuilder |
134
|
|
|
*/ |
135
|
|
|
public function withCharset($charset) |
136
|
|
|
{ |
137
|
|
|
$this->charset = $charset; |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param string $gtid |
144
|
|
|
* @return ConfigBuilder |
145
|
|
|
*/ |
146
|
|
|
public function withGtid($gtid) |
147
|
|
|
{ |
148
|
|
|
$this->gtid = $gtid; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param int $slaveId |
155
|
|
|
* @return ConfigBuilder |
156
|
|
|
*/ |
157
|
|
|
public function withSlaveId($slaveId) |
158
|
|
|
{ |
159
|
|
|
$this->slaveId = $slaveId; |
160
|
|
|
|
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param string $binLogFileName |
166
|
|
|
* @return ConfigBuilder |
167
|
|
|
*/ |
168
|
|
|
public function withBinLogFileName($binLogFileName) |
169
|
|
|
{ |
170
|
|
|
$this->binLogFileName = $binLogFileName; |
171
|
|
|
|
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param int $binLogPosition |
177
|
|
|
* @return ConfigBuilder |
178
|
|
|
*/ |
179
|
|
|
public function withBinLogPosition($binLogPosition) |
180
|
|
|
{ |
181
|
|
|
$this->binLogPosition = $binLogPosition; |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param array $eventsOnly |
188
|
|
|
* @return ConfigBuilder |
189
|
|
|
*/ |
190
|
|
|
public function withEventsOnly($eventsOnly) |
191
|
|
|
{ |
192
|
|
|
$this->eventsOnly = $eventsOnly; |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param array $eventsIgnore |
199
|
|
|
* @return ConfigBuilder |
200
|
|
|
*/ |
201
|
|
|
public function withEventsIgnore(array $eventsIgnore) |
202
|
|
|
{ |
203
|
|
|
$this->eventsIgnore = $eventsIgnore; |
204
|
|
|
|
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param array $tablesOnly |
210
|
|
|
* @return ConfigBuilder |
211
|
|
|
*/ |
212
|
|
|
public function withTablesOnly(array $tablesOnly) |
213
|
|
|
{ |
214
|
|
|
$this->tablesOnly = $tablesOnly; |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param array $databasesOnly |
221
|
|
|
* @return ConfigBuilder |
222
|
|
|
*/ |
223
|
|
|
public function withDatabasesOnly(array $databasesOnly) |
224
|
|
|
{ |
225
|
|
|
$this->databasesOnly = $databasesOnly; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param string $mariaDbGtid |
232
|
|
|
* @return ConfigBuilder |
233
|
|
|
*/ |
234
|
|
|
public function withMariaDbGtid($mariaDbGtid) |
235
|
|
|
{ |
236
|
|
|
$this->mariaDbGtid = $mariaDbGtid; |
237
|
|
|
|
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @param int $tableCacheSize |
243
|
|
|
*/ |
244
|
|
|
public function withTableCacheSize($tableCacheSize) |
245
|
|
|
{ |
246
|
|
|
$this->tableCacheSize = $tableCacheSize; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @return Config |
251
|
|
|
*/ |
252
|
|
|
public function build() |
253
|
|
|
{ |
254
|
|
|
return new Config( |
255
|
|
|
$this->user, |
256
|
|
|
$this->host, |
257
|
|
|
$this->port, |
258
|
|
|
$this->password, |
259
|
|
|
$this->dbName, |
260
|
|
|
$this->charset, |
261
|
|
|
$this->gtid, |
262
|
|
|
$this->mariaDbGtid, |
263
|
|
|
$this->slaveId, |
264
|
|
|
$this->binLogFileName, |
265
|
|
|
$this->binLogPosition, |
266
|
|
|
$this->eventsOnly, |
267
|
|
|
$this->eventsIgnore, |
268
|
|
|
$this->tablesOnly, |
269
|
|
|
$this->databasesOnly, |
270
|
|
|
$this->tableCacheSize |
271
|
|
|
); |
272
|
|
|
} |
273
|
|
|
} |