$cached =
$this->cacheBackend->
get($cache_id);
if ($cached) { return $this->
createResource($cached->data,
$url);
} try { $response =
$this->httpClient->
request('GET',
$url,
[ RequestOptions::TIMEOUT => 5,
]);
} catch (TransferException
$e) { throw new ResourceException('Could not retrieve the oEmbed resource.',
$url,
[],
$e);
} [$format] =
$response->
getHeader('Content-Type'
);
$content =
(string) $response->
getBody();
if (strstr($format, 'text/xml'
) ||
strstr($format, 'application/xml'
)) { $data =
$this->
parseResourceXml($content,
$url);
} // By default, try to parse the resource data as JSON.
else { $data = Json::
decode($content);