/** * IMPORTANT: to write-then-read slave lag issues, when a master database * has already been selected, continue using it instead of creating a replica connection * * @return PDO */ public function getReplica() { if ($this->isUsingMaster()) { return $this->_master; } if (empty($this->_replica)) { $config = null; try { $config = $this->_config->getReplica(); } catch (ConfigMissingException $e) { return $this->getMaster(); } $this->_replica = $this->_buildAdapter($config); } // if !replica return $this->_replica; }
/** * @test */ public function setMasterReplicaGetMasterReplica() { $config = new ConfigService(); $config->addMaster($this->_correct1); $config->addReplica($this->_correct2); $this->assertSame($this->_correct1, $config->getMaster()); $this->assertSame($this->_correct2, $config->getReplica()); }