$requests = array_map(
function ($service) use ($url) {
/* @var ServiceInterface $service */
return $service->getRequest($url);
},
$this->services
);
/** @var ResponseInterface[]|TransferException[] $results */
$results = Pool::batch($this->client, $requests);
$counts = [];
$i = 0;
foreach ($this->services as $service) {
if ($results[$i] instanceof TransferException) {
if ($this->logger !== null) {
$this->logger->warning($results[$i]->getMessage(), ['exception' => $results[$i]]);
}
} else {
try {
$content = $service->filterResponse($results[$i]->getBody()->getContents());
$json = json_decode($content, true);
$counts[$service->getName()] = is_array($json) ? (int) $service->extractCount($json) : 0;
} catch (\Exception $e) {
if ($this->logger !== null) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
}
}
}
++$i;
}
$this->cache->setItem($cacheKey, json_encode($counts));
return $counts;
}