$remote_thumbnail_url =
$remote_thumbnail_url->
toString();
$hash = Crypt::
hashBase64($remote_thumbnail_url);
$files =
$this->fileSystem->
scanDirectory($directory, "/^
$hash\..*/"
);
if (count($files) > 0
) { return reset($files)->uri;
} // The local thumbnail doesn't exist yet, so we need to download it.
try { $response =
$this->httpClient->
request('GET',
$remote_thumbnail_url);
if ($response->
getStatusCode() === 200
) { $local_thumbnail_uri =
$directory . DIRECTORY_SEPARATOR .
$hash . '.' .
$this->
getThumbnailFileExtensionFromUrl($remote_thumbnail_url,
$response);
$this->fileSystem->
saveData((string) $response->
getBody(),
$local_thumbnail_uri, FileSystemInterface::EXISTS_REPLACE
);
return $local_thumbnail_uri;
} } catch (TransferException
$e) { $this->logger->
warning('Failed to download remote thumbnail file due to "%error".',
[ '%error' =>
$e->
getMessage(),
]);
} catch (FileException
$e) { $this->logger->
warning('Could not download remote thumbnail from {url}.',
[