/**
  * @param Connection[] $connections
  * @param int $mode
  * @param Random $rand
  * @throws Exception when an empty array is passed
  */
 public function __construct(array $connections, $mode = self::MODE_ROUNDROBIN, Random $rand = null)
 {
     if (empty($connections)) {
         throw new Exception('need at least one connection.');
     }
     // we have to clear the keys here using array_values(), because we are working with numeric indices
     $this->connections = new ConnectionSet(array_values($connections));
     $this->connectionIterator = $this->connections->getIterator();
     $this->connectionCount = count($this->connections);
     $this->setMode($mode);
     if ($rand == null) {
         $rand = new SystemRandom();
     }
     $this->rng = $rand;
 }
 public function __construct(array $connections, Time $timer = null, LoggerInterface $log = null)
 {
     parent::__construct($connections);
     // construct connection state array
     foreach ($connections as $key => $conn) {
         $this->connState[$key] = array('state' => FailoverWrapper::CONNECTION_HEALTHY, 'failures' => 0, 'lastChange' => 0);
     }
     if ($timer === null) {
         $timer = new SystemTime();
     }
     $this->timer = $timer;
     if ($log === null) {
         $log = new NullLog();
     }
     $this->log = $log;
 }
Example #3
0
 public function testGetSingleKey()
 {
     $this->set = new ConnectionSet(array('key1' => $this->conn1));
     $this->assertSame('key1', $this->set->getSingleKey());
 }