/** * {@inheritdoc} */ public function add(IConnectionSingle $connection) { $parameters = $connection->getParameters(); if (isset($parameters->alias)) { $this->_pool[$parameters->alias] = $connection; } else { $this->_pool[] = $connection; } $this->_distributor->add($connection, $parameters->weight); }
/** * {@inheritdoc} */ public function remove(IConnectionSingle $connection) { if ($connection->getParameters()->alias === 'master') { $this->master = null; $this->reset(); return true; } else { if (($id = array_search($connection, $this->slaves, true)) !== false) { unset($this->slaves[$id]); $this->reset(); return true; } } return false; }
/** * {@inheritdoc} */ public function executeCommand(ICommand $command) { if (null === $this->logger) { return $this->connection->executeCommand($command); } $startTime = microtime(true); $result = $this->connection->executeCommand($command); $duration = (microtime(true) - $startTime) * 1000; $error = $result instanceof ResponseError ? (string) $result : false; $this->logger->logCommand((string) $command, $duration, $this->getParameters()->alias, $error); return $result; }
/** * Prepares a connection object after its initialization. * * @param IConnectionSingle $connection Instance of a connection object. * @param IServerProfile $profile $connection Instance of a connection object. */ protected function prepareConnection(IConnectionSingle $connection, IServerProfile $profile) { $parameters = $connection->getParameters(); if (isset($parameters->password)) { $command = $profile->createCommand('auth', array($parameters->password)); $connection->pushInitCommand($command); } if (isset($parameters->database)) { $command = $profile->createCommand('select', array($parameters->database)); $connection->pushInitCommand($command); } }