1<?php 2 3declare(strict_types = 1); 4 5namespace Elasticsearch\ConnectionPool\Selectors; 6 7use Elasticsearch\Connections\ConnectionInterface; 8 9/** 10 * Class RoundRobinSelector 11 * 12 * @category Elasticsearch 13 * @package Elasticsearch\ConnectionPool\Selectors\ConnectionPool 14 * @author Zachary Tong <zach@elastic.co> 15 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 16 * @link http://elastic.co 17 */ 18class RoundRobinSelector implements SelectorInterface 19{ 20 /** 21 * @var int 22 */ 23 private $current = 0; 24 25 /** 26 * Select the next connection in the sequence 27 * 28 * @param ConnectionInterface[] $connections an array of ConnectionInterface instances to choose from 29 */ 30 public function select(array $connections): ConnectionInterface 31 { 32 $returnConnection = $connections[$this->current % count($connections)]; 33 34 $this->current += 1; 35 36 return $returnConnection; 37 } 38} 39