function ComposerRepository::startCachedAsyncDownload
@phpstan-return PromiseInterface<array{mixed, string}>
File
-
vendor/
composer/ composer/ src/ Composer/ Repository/ ComposerRepository.php, line 1093
Class
- ComposerRepository
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\RepositoryCode
private function startCachedAsyncDownload(string $fileName, ?string $packageName = null) : PromiseInterface {
if (null === $this->lazyProvidersUrl) {
throw new \LogicException('startCachedAsyncDownload only supports v2 protocol composer repos with a metadata-url');
}
$name = strtolower($fileName);
$packageName = $packageName ?? $name;
$url = str_replace('%package%', $name, $this->lazyProvidersUrl);
$cacheKey = 'provider-' . strtr($name, '/', '~') . '.json';
$lastModified = null;
if ($contents = $this->cache
->read($cacheKey)) {
$contents = json_decode($contents, true);
$lastModified = $contents['last-modified'] ?? null;
}
return $this->asyncFetchFile($url, $cacheKey, $lastModified)
->then(static function ($response) use ($url, $cacheKey, $contents, $packageName) : array {
$packagesSource = 'downloaded file (' . Url::sanitize($url) . ')';
if (true === $response) {
$packagesSource = 'cached file (' . $cacheKey . ' originating from ' . Url::sanitize($url) . ')';
$response = $contents;
}
if (!isset($response['packages'][$packageName]) && !isset($response['security-advisories'])) {
return [
null,
$packagesSource,
];
}
return [
$response,
$packagesSource,
];
});
}