Skip to content

Commit a8a03f5

Browse files
committed
current changes
1 parent 0bd4960 commit a8a03f5

File tree

10 files changed

+152
-198
lines changed

10 files changed

+152
-198
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Changed inserts to not existing tables/columns will be returned as WriteEvent with empty Fields (see BasicTest::shouldGetWriteEventDropTable)
2222
- Changed TABLE_MAP_EVENT will no longer appear after adding events to only/ignore configuration
2323
- Fixed events with dropped columns will return a proper columns amount
24+
- Changed configuration to static calls
2425

2526
## v2.2.0 (2017-03-10)
2627
- Removed foreign keys from events

src/MySQLReplication/BinLog/BinLogSocketConnect.php

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ class BinLogSocketConnect
2525
* @var RepositoryInterface
2626
*/
2727
private $repository;
28-
/**
29-
* @var Config
30-
*/
31-
private $config;
3228
/**
3329
* http://dev.mysql.com/doc/internals/en/auth-phase-fast-path.html 00 FE
3430
* @var array
@@ -45,23 +41,20 @@ class BinLogSocketConnect
4541
private $binaryDataMaxLength = 16777215;
4642

4743
/**
48-
* @param Config $config
4944
* @param RepositoryInterface $repository
5045
* @param SocketInterface $socket
5146
* @throws BinLogException
5247
* @throws \MySQLReplication\Gtid\GtidException
5348
* @throws \MySQLReplication\Socket\SocketException
5449
*/
5550
public function __construct(
56-
Config $config,
5751
RepositoryInterface $repository,
5852
SocketInterface $socket
5953
) {
6054
$this->repository = $repository;
61-
$this->config = $config;
6255
$this->socket = $socket;
6356

64-
$this->socket->connectToStream($this->config->getHost(), $this->config->getPort());
57+
$this->socket->connectToStream(Config::getHost(), Config::getPort());
6558
BinLogServerInfo::parsePackage($this->getResponse(false), $this->repository->getVersion());
6659
$this->authenticate();
6760
$this->getBinlogStream();
@@ -129,9 +122,9 @@ private function authenticate()
129122
for ($i = 0; $i < 23; $i++) {
130123
$data .= chr(0);
131124
}
132-
$result = sha1($this->config->getPassword(), true) ^ sha1(BinLogServerInfo::getSalt() . sha1(sha1($this->config->getPassword(), true), true), true);
125+
$result = sha1(Config::getPassword(), true) ^ sha1(BinLogServerInfo::getSalt() . sha1(sha1(Config::getPassword(), true), true), true);
133126

134-
$data = $data . $this->config->getUser() . chr(0) . chr(strlen($result)) . $result;
127+
$data = $data . Config::getUser() . chr(0) . chr(strlen($result)) . $result;
135128
$str = pack('L', strlen($data));
136129
$s = $str[0] . $str[1] . $str[2];
137130
$data = $s . chr(1) . $data;
@@ -154,7 +147,7 @@ private function getBinlogStream()
154147

155148
$this->registerSlave();
156149

157-
if ('' !== $this->config->getGtid()) {
150+
if ('' !== Config::getGtid()) {
158151
$this->setBinLogDumpGtid();
159152
} else {
160153
$this->setBinLogDump();
@@ -181,19 +174,19 @@ private function registerSlave()
181174
{
182175
$host = gethostname();
183176
$hostLength = strlen($host);
184-
$userLength = strlen($this->config->getUser());
185-
$passLength = strlen($this->config->getPassword());
177+
$userLength = strlen(Config::getUser());
178+
$passLength = strlen(Config::getPassword());
186179

187180
$data = pack('l', 18 + $hostLength + $userLength + $passLength);
188181
$data .= chr(ConstCommand::COM_REGISTER_SLAVE);
189-
$data .= pack('V', $this->config->getSlaveId());
182+
$data .= pack('V', Config::getSlaveId());
190183
$data .= pack('C', $hostLength);
191184
$data .= $host;
192185
$data .= pack('C', $userLength);
193-
$data .= $this->config->getUser();
186+
$data .= Config::getUser();
194187
$data .= pack('C', $passLength);
195-
$data .= $this->config->getPassword();
196-
$data .= pack('v', $this->config->getPort());
188+
$data .= Config::getPassword();
189+
$data .= pack('v', Config::getPort());
197190
$data .= pack('V', 0);
198191
$data .= pack('V', 0);
199192

@@ -209,11 +202,11 @@ private function registerSlave()
209202
*/
210203
private function setBinLogDumpGtid()
211204
{
212-
$collection = GtidFactory::makeCollectionFromString($this->config->getGtid());
205+
$collection = GtidFactory::makeCollectionFromString(Config::getGtid());
213206

214207
$data = pack('l', 26 + $collection->getEncodedLength()) . chr(ConstCommand::COM_BINLOG_DUMP_GTID);
215208
$data .= pack('S', 0);
216-
$data .= pack('I', $this->config->getSlaveId());
209+
$data .= pack('I', Config::getSlaveId());
217210
$data .= pack('I', 3);
218211
$data .= chr(0);
219212
$data .= chr(0);
@@ -233,15 +226,15 @@ private function setBinLogDumpGtid()
233226
*/
234227
private function setBinLogDump()
235228
{
236-
if ('' !== $this->config->getMariaDbGtid()) {
229+
if ('' !== Config::getMariaDbGtid()) {
237230
$this->execute('SET @mariadb_slave_capability = 4');
238-
$this->execute('SET @slave_connect_state = \'' . $this->config->getMariaDbGtid() . '\'');
231+
$this->execute('SET @slave_connect_state = \'' . Config::getMariaDbGtid() . '\'');
239232
$this->execute('SET @slave_gtid_strict_mode = 0');
240233
$this->execute('SET @slave_gtid_ignore_duplicates = 0');
241234
}
242235

243-
$binFilePos = $this->config->getBinLogPosition();
244-
$binFileName = $this->config->getBinLogFileName();
236+
$binFilePos = Config::getBinLogPosition();
237+
$binFileName = Config::getBinLogFileName();
245238
if (0 === $binFilePos || '' === $binFileName) {
246239
$master = $this->repository->getMasterStatus();
247240
$binFilePos = $master['Position'];
@@ -251,7 +244,7 @@ private function setBinLogDump()
251244
$data = pack('i', strlen($binFileName) + 11) . chr(ConstCommand::COM_BINLOG_DUMP);
252245
$data .= pack('I', $binFilePos);
253246
$data .= pack('v', 0);
254-
$data .= pack('I', $this->config->getSlaveId());
247+
$data .= pack('I', Config::getSlaveId());
255248
$data .= $binFileName;
256249

257250
$this->socket->writeToSocket($data);

src/MySQLReplication/Cache/ArrayCache.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,7 @@ class ArrayCache implements CacheInterface
1515
* @var array
1616
*/
1717
private static $tableMapCache = [];
18-
/**
19-
* @var Config
20-
*/
21-
private $config;
22-
23-
/**
24-
* ArrayCache constructor.
25-
* @param Config $config
26-
*/
27-
public function __construct(Config $config)
28-
{
29-
$this->config = $config;
30-
}
31-
18+
3219
/**
3320
* Fetches a value from the cache.
3421
*
@@ -62,10 +49,10 @@ public function get($key, $default = null)
6249
public function set($key, $value, $ttl = null)
6350
{
6451
// automatically clear table cache to save memory
65-
if (count(self::$tableMapCache) > $this->config->getTableCacheSize()) {
52+
if (count(self::$tableMapCache) > Config::getTableCacheSize()) {
6653
self::$tableMapCache = array_slice(
6754
self::$tableMapCache,
68-
ceil($this->config->getTableCacheSize() / 2),
55+
ceil(Config::getTableCacheSize() / 2),
6956
null,
7057
true
7158
);

0 commit comments

Comments
 (0)