_connections = $connections; $this->_strategy = $strategy; $this->_callback = $callback; } /** * @param \Elastica\Connection $connection * * @return $this */ public function addConnection(Connection $connection) { $this->_connections[] = $connection; return $this; } /** * @param array|\Elastica\Connection[] $connections * * @return $this */ public function setConnections(array $connections) { $this->_connections = $connections; return $this; } /** * @return bool */ public function hasConnection() { foreach ($this->_connections as $connection) { if ($connection->isEnabled()) { return true; } } return false; } /** * @return array */ public function getConnections() { return $this->_connections; } /** * @throws \Elastica\Exception\ClientException * * @return \Elastica\Connection */ public function getConnection() { return $this->_strategy->getConnection($this->getConnections()); } /** * @param \Elastica\Connection $connection * @param \Exception $e * @param Client $client */ public function onFail(Connection $connection, Exception $e, Client $client) { $connection->setEnabled(false); if ($this->_callback) { call_user_func($this->_callback, $connection, $e, $client); } } /** * @return \Elastica\Connection\Strategy\StrategyInterface */ public function getStrategy() { return $this->_strategy; } }