Example #1
0
 /**
  * {@inheritdoc}
  */
 public function add(SingleConnectionInterface $connection)
 {
     $parameters = $connection->getParameters();
     if (isset($parameters->alias)) {
         $this->pool[$parameters->alias] = $connection;
     } else {
         $this->pool[] = $connection;
     }
     $weight = isset($parameters->weight) ? $parameters->weight : null;
     $this->distributor->add($connection, $weight);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function remove(SingleConnectionInterface $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;
 }
 /**
  * Prepares a connection object after its initialization.
  *
  * @param SingleConnectionInterface $connection Instance of a connection object.
  */
 protected function prepareConnection(SingleConnectionInterface $connection)
 {
     if (isset($this->profile)) {
         $parameters = $connection->getParameters();
         if (isset($parameters->password)) {
             $command = $this->profile->createCommand('auth', array($parameters->password));
             $connection->pushInitCommand($command);
         }
         if (isset($parameters->database)) {
             $command = $this->profile->createCommand('select', array($parameters->database));
             $connection->pushInitCommand($command);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getParameters()
 {
     return $this->connection->getParameters();
 }