Fix using inside anonymous function

main
Fränz Friederes 4 years ago
parent 57e1ce6cdb
commit a1a3e29f52
No known key found for this signature in database
GPG Key ID: 583D205C93C01BC0

@ -106,6 +106,11 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
throw new \InvalidArgumentException('The given package is missing url information');
}
$generateCacheKey = function (PackageInterface $package, $key) {
$cacheKey = sha1($key);
return $package->getName().'/'.$cacheKey.'.'.$package->getDistType();
};
$retries = 3;
$urls = $package->getDistUrls();
foreach ($urls as $index => $url) {
@ -117,7 +122,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
// from different packages, which would potentially allow a given package
// in a third party repo to pre-populate the cache for the same package in
// packagist for example.
'cacheKey' => $this->getCacheKey($package, $processedUrl)
'cacheKey' => $generateCacheKey($package, $processedUrl)
);
}
@ -134,16 +139,16 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$accept = null;
$reject = null;
$download = function () use ($io, $output, $httpDownloader, $cache, $eventDispatcher, $package, $fileName, &$urls, &$accept, &$reject) {
$download = function () use ($io, $output, $httpDownloader, $cache, $generateCacheKey, $eventDispatcher, $package, $fileName, &$urls, &$accept, &$reject) {
$url = reset($urls);
if ($eventDispatcher) {
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $httpDownloader, $url['processed'], 'package', $package);
$eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
if ($preFileDownloadEvent->getCustomCacheKey() !== null) {
$url['cacheKey'] = $this->getCacheKey($package, $preFileDownloadEvent->getCustomCacheKey());
$url['cacheKey'] = $generateCacheKey($package, $preFileDownloadEvent->getCustomCacheKey());
} else if ($preFileDownloadEvent->getProcessedUrl() !== $url['processed']) {
$url['cacheKey'] = $this->getCacheKey($package, $preFileDownloadEvent->getProcessedUrl());
$url['cacheKey'] = $generateCacheKey($package, $preFileDownloadEvent->getProcessedUrl());
}
$url['processed'] = $preFileDownloadEvent->getProcessedUrl();
}
@ -407,12 +412,6 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
return $url;
}
private function getCacheKey(PackageInterface $package, $key)
{
$cacheKey = sha1($key);
return $package->getName().'/'.$cacheKey.'.'.$package->getDistType();
}
/**
* {@inheritDoc}
* @throws \RuntimeException

Loading…
Cancel
Save