Simple.php 645 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Elastica\Connection\Strategy;
  3. use Elastica\Exception\ClientException;
  4. /**
  5. * Description of SimpleStrategy.
  6. *
  7. * @author chabior
  8. */
  9. class Simple implements StrategyInterface
  10. {
  11. /**
  12. * @param array|\Elastica\Connection[] $connections
  13. *
  14. * @throws \Elastica\Exception\ClientException
  15. *
  16. * @return \Elastica\Connection
  17. */
  18. public function getConnection($connections)
  19. {
  20. foreach ($connections as $connection) {
  21. if ($connection->isEnabled()) {
  22. return $connection;
  23. }
  24. }
  25. throw new ClientException('No enabled connection');
  26. }
  27. }