/** * @param MasterSlaveConnection $connection * @return Success|Failure */ private function checkMasterSlaveConnection(MasterSlaveConnection $connection) { // TODO Check all slaves, instead of random one if possible. $connection->connect('slave'); $isSlaveConnected = $connection->ping(); $connection->connect('master'); $isMasterConnected = $connection->ping(); $data = ['slave' => $isSlaveConnected ? 'connected' : 'not connected', 'master' => $isMasterConnected ? 'connected' : 'not connected']; if ($isMasterConnected && $isSlaveConnected) { return new Success(get_class($connection), $data); } return new Failure(get_class($connection), $data); }
/** * {@inheritdoc} */ public function connect($connectionName = null) { try { return parent::connect($connectionName); } catch (DBALException $e) { if ($this->_eventManager->hasListeners('failConnect')) { $eventArgs = new FailedConnectionEvent($this, $e); $this->_eventManager->dispatchEvent('failConnect', $eventArgs); } } }