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