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