1 | <?php |
||
32 | class Client implements ClientInterface |
||
33 | { |
||
34 | |||
35 | const DEFAULT_SERVER = "localhost:4200"; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $availableServers = []; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private $serverPool = []; |
||
46 | |||
47 | /** |
||
48 | * Client constructor. |
||
49 | * @param array $servers |
||
50 | * @param array $options |
||
51 | */ |
||
52 | 1 | public function __construct(array $servers, array $options) |
|
64 | |||
65 | /** |
||
66 | * {@Inheritdoc} |
||
67 | */ |
||
68 | 2 | public function execute($query, array $parameters) |
|
118 | |||
119 | /** |
||
120 | * {@Inheritdoc} |
||
121 | */ |
||
122 | 1 | public function getServerInfo() |
|
123 | { |
||
124 | 1 | throw new UnsupportedException('Not yet implemented'); |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * {@Inheritdoc} |
||
129 | */ |
||
130 | 1 | public function getServerVersion() |
|
131 | { |
||
132 | 1 | throw new UnsupportedException('Not yet implemented'); |
|
133 | } |
||
134 | |||
135 | /** |
||
136 | * {@Inheritdoc} |
||
137 | */ |
||
138 | 1 | public function setTimeout($timeout) |
|
139 | { |
||
140 | 1 | foreach ($this->serverPool as $k => &$s) { |
|
141 | /** |
||
142 | * @var $s Server |
||
143 | */ |
||
144 | 1 | $s->setTimeout($timeout); |
|
145 | 1 | } |
|
146 | 1 | } |
|
147 | |||
148 | /** |
||
149 | * {@Inheritdoc} |
||
150 | */ |
||
151 | public function setHttpBasicAuth($username, $passwd) |
||
160 | |||
161 | /** |
||
162 | * {@Inheritdoc} |
||
163 | */ |
||
164 | public function setHttpHeader($name, $value) |
||
173 | |||
174 | /** |
||
175 | * {@Inheritdoc} |
||
176 | */ |
||
177 | 1 | public function setDefaultSchema($schemaName) |
|
178 | { |
||
179 | 1 | $this->setHttpHeader("Default-Schema", $schemaName); |
|
180 | 1 | } |
|
181 | |||
182 | /** |
||
183 | * @return string The next available server instance |
||
184 | */ |
||
185 | 3 | private function nextServer() |
|
191 | |||
192 | /** |
||
193 | * Very simple round-robin implementation |
||
194 | * Pops the first item of the availableServers array and appends it at the end. |
||
195 | * |
||
196 | * @return void |
||
197 | */ |
||
198 | 3 | private function roundRobin() |
|
208 | |||
209 | /** |
||
210 | * @param string $server |
||
211 | */ |
||
212 | 2 | private function dropServer($server) |
|
218 | |||
219 | /** |
||
220 | * @param ConnectException $exception |
||
221 | */ |
||
222 | 1 | private function raiseIfNoMoreServers($exception) |
|
231 | } |
||
232 |