|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace MySQLReplication\Config; |
|
5
|
|
|
|
|
6
|
|
|
class ConfigBuilder |
|
7
|
|
|
{ |
|
8
|
|
|
private $user = ''; |
|
9
|
|
|
private $host = 'localhost'; |
|
10
|
|
|
private $port = 3306; |
|
11
|
|
|
private $password = ''; |
|
12
|
|
|
private $charset = 'utf8'; |
|
13
|
|
|
private $gtid = ''; |
|
14
|
|
|
private $slaveId = 666; |
|
15
|
|
|
private $binLogFileName = ''; |
|
16
|
|
|
private $binLogPosition = 0; |
|
17
|
|
|
private $eventsOnly = []; |
|
18
|
|
|
private $eventsIgnore = []; |
|
19
|
|
|
private $tablesOnly = []; |
|
20
|
|
|
private $databasesOnly = []; |
|
21
|
|
|
private $mariaDbGtid = ''; |
|
22
|
|
|
private $tableCacheSize = 128; |
|
23
|
|
|
private $custom = []; |
|
24
|
|
|
private $heartbeatPeriod = 0.0; |
|
25
|
|
|
private $retry = 0; |
|
26
|
|
|
|
|
27
|
|
|
public function withUser(string $user): self |
|
28
|
|
|
{ |
|
29
|
|
|
$this->user = $user; |
|
30
|
|
|
|
|
31
|
|
|
return $this; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function withHost(string $host): self |
|
35
|
|
|
{ |
|
36
|
|
|
$this->host = $host; |
|
37
|
|
|
|
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function withPort(int $port): self |
|
42
|
|
|
{ |
|
43
|
|
|
$this->port = $port; |
|
44
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function withPassword(string $password): self |
|
49
|
|
|
{ |
|
50
|
|
|
$this->password = $password; |
|
51
|
|
|
|
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function withCharset(string $charset): self |
|
56
|
|
|
{ |
|
57
|
|
|
$this->charset = $charset; |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function withGtid(string $gtid): self |
|
63
|
|
|
{ |
|
64
|
|
|
$this->gtid = $gtid; |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function withSlaveId(int $slaveId): self |
|
70
|
|
|
{ |
|
71
|
|
|
$this->slaveId = $slaveId; |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function withBinLogFileName(string $binLogFileName): self |
|
77
|
|
|
{ |
|
78
|
|
|
$this->binLogFileName = $binLogFileName; |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function withBinLogPosition(int $binLogPosition): self |
|
84
|
|
|
{ |
|
85
|
|
|
$this->binLogPosition = $binLogPosition; |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function withEventsOnly(array $eventsOnly): self |
|
91
|
|
|
{ |
|
92
|
|
|
$this->eventsOnly = $eventsOnly; |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function withEventsIgnore(array $eventsIgnore): self |
|
98
|
|
|
{ |
|
99
|
|
|
$this->eventsIgnore = $eventsIgnore; |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function withTablesOnly(array $tablesOnly): self |
|
105
|
|
|
{ |
|
106
|
|
|
$this->tablesOnly = $tablesOnly; |
|
107
|
|
|
|
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function withDatabasesOnly(array $databasesOnly): self |
|
112
|
|
|
{ |
|
113
|
|
|
$this->databasesOnly = $databasesOnly; |
|
114
|
|
|
|
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function withMariaDbGtid(string $mariaDbGtid): self |
|
119
|
|
|
{ |
|
120
|
|
|
$this->mariaDbGtid = $mariaDbGtid; |
|
121
|
|
|
|
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
public function withTableCacheSize(int $tableCacheSize): self |
|
127
|
|
|
{ |
|
128
|
|
|
$this->tableCacheSize = $tableCacheSize; |
|
129
|
|
|
|
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
public function withCustom(array $custom): self |
|
135
|
|
|
{ |
|
136
|
|
|
$this->custom = $custom; |
|
137
|
|
|
|
|
138
|
|
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @see https://dev.mysql.com/doc/refman/5.6/en/change-master-to.html |
|
143
|
|
|
*/ |
|
144
|
|
|
public function withHeartbeatPeriod(float $heartbeatPeriod): self |
|
145
|
|
|
{ |
|
146
|
|
|
$this->heartbeatPeriod = $heartbeatPeriod; |
|
147
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function withRetry(int $retry): self |
|
152
|
|
|
{ |
|
153
|
|
|
$this->retry = $retry; |
|
154
|
|
|
|
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function build(): Config |
|
159
|
|
|
{ |
|
160
|
|
|
return new Config( |
|
161
|
|
|
$this->user, |
|
162
|
|
|
$this->host, |
|
163
|
|
|
$this->port, |
|
164
|
|
|
$this->password, |
|
165
|
|
|
$this->charset, |
|
166
|
|
|
$this->gtid, |
|
167
|
|
|
$this->mariaDbGtid, |
|
168
|
|
|
$this->slaveId, |
|
169
|
|
|
$this->binLogFileName, |
|
170
|
|
|
$this->binLogPosition, |
|
171
|
|
|
$this->eventsOnly, |
|
172
|
|
|
$this->eventsIgnore, |
|
173
|
|
|
$this->tablesOnly, |
|
174
|
|
|
$this->databasesOnly, |
|
175
|
|
|
$this->tableCacheSize, |
|
176
|
|
|
$this->custom, |
|
177
|
|
|
$this->heartbeatPeriod, |
|
178
|
|
|
$this->retry |
|
179
|
|
|
); |
|
180
|
|
|
} |
|
181
|
|
|
} |