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