1 | <?php |
||
30 | class HttpClientPoolItem implements HttpClient, HttpAsyncClient |
||
31 | { |
||
32 | /** |
||
33 | * @var int Number of request this client is currently sending |
||
34 | */ |
||
35 | private $sendingRequestCount = 0; |
||
36 | |||
37 | /** |
||
38 | * @var \DateTime|null Time when this client has been disabled or null if enable |
||
39 | */ |
||
40 | private $disabledAt; |
||
41 | |||
42 | /** |
||
43 | * Number of seconds until this client is enabled again after an error. |
||
44 | * |
||
45 | * null: never reenable this client. |
||
46 | * |
||
47 | * @var int|null |
||
48 | */ |
||
49 | private $reenableAfter; |
||
50 | |||
51 | /** |
||
52 | * @var FlexibleHttpClient A http client responding to async and sync request |
||
53 | */ |
||
54 | private $client; |
||
55 | |||
56 | /** |
||
57 | * @param ClientInterface|HttpAsyncClient $client |
||
58 | * @param null|int $reenableAfter Number of seconds until this client is enabled again after an error |
||
59 | */ |
||
60 | 23 | public function __construct($client, $reenableAfter = null) |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 13 | public function sendRequest(RequestInterface $request): ResponseInterface |
|
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | 8 | public function sendAsyncRequest(RequestInterface $request) |
|
111 | |||
112 | /** |
||
113 | * Whether this client is disabled or not. |
||
114 | * |
||
115 | * If the client was disabled, calling this method checks if the client can |
||
116 | * be reenabled and if so enables it. |
||
117 | */ |
||
118 | 21 | public function isDisabled(): bool |
|
135 | |||
136 | /** |
||
137 | * Get current number of request that are currently being sent by the underlying HTTP client. |
||
138 | */ |
||
139 | 2 | public function getSendingRequestCount(): int |
|
143 | |||
144 | /** |
||
145 | * Increment the request count. |
||
146 | */ |
||
147 | 21 | private function incrementRequestCount() |
|
151 | |||
152 | /** |
||
153 | * Decrement the request count. |
||
154 | */ |
||
155 | 16 | private function decrementRequestCount() |
|
159 | |||
160 | /** |
||
161 | * Enable the current client. |
||
162 | */ |
||
163 | 5 | private function enable() |
|
167 | |||
168 | /** |
||
169 | * Disable the current client. |
||
170 | */ |
||
171 | 10 | private function disable() |
|
175 | } |
||
176 |