RandomSelector.php 794 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Elasticsearch\ConnectionPool\Selectors;
  3. use Elasticsearch\Connections\ConnectionInterface;
  4. /**
  5. * Class RandomSelector
  6. *
  7. * @category Elasticsearch
  8. * @package Elasticsearch\Connections\Selectors\RandomSelector
  9. * @author Zachary Tong <zach@elastic.co>
  10. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  11. * @link http://elastic.co
  12. */
  13. class RandomSelector implements SelectorInterface
  14. {
  15. /**
  16. * Select a random connection from the provided array
  17. *
  18. * @param ConnectionInterface[] $connections an array of ConnectionInterface instances to choose from
  19. *
  20. * @return \Elasticsearch\Connections\ConnectionInterface
  21. */
  22. public function select($connections)
  23. {
  24. return $connections[array_rand($connections)];
  25. }
  26. }