/**
  * @throws Ackintosh\Higher\Exceptions\TransactionException
  */
 public function get($location, $useSlave = false)
 {
     // If we have no configuration for slave,
     // ConnectionManager uses master connection.
     if ($useSlave === true && count($this->config->getConnectionConfig($location, 'slaves')) === 0) {
         $useSlave = false;
     }
     if ($useSlave === false) {
         $param = $this->config->getConnectionConfig($location);
         $connectionKey = 'master';
     } else {
         $params = $this->config->getConnectionConfig($location, 'slaves');
         $slaveKey = array_rand($params);
         $param = $params[$slaveKey];
         $connectionKey = 'slave' . $slaveKey;
     }
     if (isset($this->connections[$location][$connectionKey])) {
         return $this->connections[$location][$connectionKey];
     }
     $connection = (new Connection($param))->setUp();
     if ($this->beginTransaction === true && $connection->beginTransaction() === false) {
         throw TransactionException::beginFailed();
     }
     $this->connections[$location][$connectionKey] = $connection;
     return $this->connections[$location][$connectionKey];
 }
Exemple #2
0
 private function instantiateTable($tableName)
 {
     $tableClassName = $this->getClassName($tableName);
     require_once $this->config->getTableDir() . "/{$tableClassName}.php";
     $table = new $tableClassName();
     return $table;
 }