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
|
62 |
|
public function withUser(string $user): self |
28
|
|
|
{ |
29
|
62 |
|
$this->user = $user; |
30
|
|
|
|
31
|
62 |
|
return $this; |
32
|
|
|
} |
33
|
|
|
|
34
|
63 |
|
public function withHost(string $host): self |
35
|
|
|
{ |
36
|
63 |
|
$this->host = $host; |
37
|
|
|
|
38
|
63 |
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
63 |
|
public function withPort(int $port): self |
42
|
|
|
{ |
43
|
63 |
|
$this->port = $port; |
44
|
|
|
|
45
|
63 |
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
62 |
|
public function withPassword(string $password): self |
49
|
|
|
{ |
50
|
62 |
|
$this->password = $password; |
51
|
|
|
|
52
|
62 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function withCharset(string $charset): self |
56
|
|
|
{ |
57
|
|
|
$this->charset = $charset; |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public function withGtid(string $gtid): self |
63
|
|
|
{ |
64
|
1 |
|
$this->gtid = $gtid; |
65
|
|
|
|
66
|
1 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
public function withSlaveId(int $slaveId): self |
70
|
|
|
{ |
71
|
1 |
|
$this->slaveId = $slaveId; |
72
|
|
|
|
73
|
1 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function withBinLogFileName(string $binLogFileName): self |
77
|
|
|
{ |
78
|
|
|
$this->binLogFileName = $binLogFileName; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
1 |
|
public function withBinLogPosition(int $binLogPosition): self |
84
|
|
|
{ |
85
|
1 |
|
$this->binLogPosition = $binLogPosition; |
86
|
|
|
|
87
|
1 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
5 |
|
public function withEventsOnly(array $eventsOnly): self |
91
|
|
|
{ |
92
|
5 |
|
$this->eventsOnly = $eventsOnly; |
93
|
|
|
|
94
|
5 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
63 |
|
public function withEventsIgnore(array $eventsIgnore): self |
98
|
|
|
{ |
99
|
63 |
|
$this->eventsIgnore = $eventsIgnore; |
100
|
|
|
|
101
|
63 |
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
2 |
|
public function withTablesOnly(array $tablesOnly): self |
105
|
|
|
{ |
106
|
2 |
|
$this->tablesOnly = $tablesOnly; |
107
|
|
|
|
108
|
2 |
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
1 |
|
public function withDatabasesOnly(array $databasesOnly): self |
112
|
|
|
{ |
113
|
1 |
|
$this->databasesOnly = $databasesOnly; |
114
|
|
|
|
115
|
1 |
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function withMariaDbGtid(string $mariaDbGtid): self |
119
|
|
|
{ |
120
|
|
|
$this->mariaDbGtid = $mariaDbGtid; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
2 |
|
public function withTableCacheSize(int $tableCacheSize): self |
127
|
|
|
{ |
128
|
2 |
|
$this->tableCacheSize = $tableCacheSize; |
129
|
|
|
|
130
|
2 |
|
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
|
7 |
|
public function withHeartbeatPeriod(float $heartbeatPeriod): self |
145
|
|
|
{ |
146
|
7 |
|
$this->heartbeatPeriod = $heartbeatPeriod; |
147
|
|
|
|
148
|
7 |
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function withRetry(int $retry): self |
152
|
|
|
{ |
153
|
|
|
$this->retry = $retry; |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
79 |
|
public function build(): Config |
159
|
|
|
{ |
160
|
79 |
|
return new Config( |
161
|
79 |
|
$this->user, |
162
|
79 |
|
$this->host, |
163
|
79 |
|
$this->port, |
164
|
79 |
|
$this->password, |
165
|
79 |
|
$this->charset, |
166
|
79 |
|
$this->gtid, |
167
|
79 |
|
$this->mariaDbGtid, |
168
|
79 |
|
$this->slaveId, |
169
|
79 |
|
$this->binLogFileName, |
170
|
79 |
|
$this->binLogPosition, |
171
|
79 |
|
$this->eventsOnly, |
172
|
79 |
|
$this->eventsIgnore, |
173
|
79 |
|
$this->tablesOnly, |
174
|
79 |
|
$this->databasesOnly, |
175
|
79 |
|
$this->tableCacheSize, |
176
|
79 |
|
$this->custom, |
177
|
79 |
|
$this->heartbeatPeriod, |
178
|
79 |
|
$this->retry |
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
} |