diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 54acae710..4f64a9501 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -106,21 +106,19 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface $io = $this->io; $cache = $this->cache; - $originalHttpDownloader = $this->httpDownloader; + $httpDownloader = $this->httpDownloader; $eventDispatcher = $this->eventDispatcher; $filesystem = $this->filesystem; $self = $this; $accept = null; $reject = null; - $download = function () use ($io, $output, $originalHttpDownloader, $cache, $eventDispatcher, $package, $fileName, $path, &$urls, &$accept, &$reject) { + $download = function () use ($io, $output, $httpDownloader, $cache, $eventDispatcher, $package, $fileName, $path, &$urls, &$accept, &$reject) { $url = reset($urls); - $httpDownloader = $originalHttpDownloader; if ($eventDispatcher) { $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $httpDownloader, $url['processed']); $eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent); - $httpDownloader = $preFileDownloadEvent->getHttpDownloader(); } $checksum = $package->getDistSha1Checksum(); diff --git a/src/Composer/Plugin/PreFileDownloadEvent.php b/src/Composer/Plugin/PreFileDownloadEvent.php index 076449484..c2751da02 100644 --- a/src/Composer/Plugin/PreFileDownloadEvent.php +++ b/src/Composer/Plugin/PreFileDownloadEvent.php @@ -25,7 +25,7 @@ class PreFileDownloadEvent extends Event /** * @var HttpDownloader */ - private $rfs; + private $httpDownloader; /** * @var string @@ -36,13 +36,13 @@ class PreFileDownloadEvent extends Event * Constructor. * * @param string $name The event name - * @param HttpDownloader $rfs + * @param HttpDownloader $httpDownloader * @param string $processedUrl */ - public function __construct($name, HttpDownloader $rfs, $processedUrl) + public function __construct($name, HttpDownloader $httpDownloader, $processedUrl) { parent::__construct($name); - $this->rfs = $rfs; + $this->httpDownloader = $httpDownloader; $this->processedUrl = $processedUrl; } @@ -51,15 +51,7 @@ class PreFileDownloadEvent extends Event */ public function getHttpDownloader() { - return $this->rfs; - } - - /** - * @param HttpDownloader $rfs - */ - public function setHttpDownloader(HttpDownloader $rfs) - { - $this->rfs = $rfs; + return $this->httpDownloader; } /** diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index af627df73..e905f2b22 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -898,15 +898,12 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $retries = 3; while ($retries--) { try { - $httpDownloader = $this->httpDownloader; - if ($this->eventDispatcher) { $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename); $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent); - $httpDownloader = $preFileDownloadEvent->getHttpDownloader(); } - $response = $httpDownloader->get($filename, $this->options); + $response = $this->httpDownloader->get($filename, $this->options); $json = $response->getBody(); if ($sha256 && $sha256 !== hash('sha256', $json)) { // undo downgrade before trying again if http seems to be hijacked or modifying content somehow @@ -989,12 +986,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $retries = 3; while ($retries--) { try { - $httpDownloader = $this->httpDownloader; - if ($this->eventDispatcher) { $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename); $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent); - $httpDownloader = $preFileDownloadEvent->getHttpDownloader(); } $options = $this->options; @@ -1002,7 +996,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $options['http']['header'] = (array) $options['http']['header']; } $options['http']['header'][] = array('If-Modified-Since: '.$lastModifiedTime); - $response = $httpDownloader->get($filename, $options); + $response = $this->httpDownloader->get($filename, $options); $json = $response->getBody(); if ($json === '' && $response->getStatusCode() === 304) { return true; @@ -1053,12 +1047,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito private function asyncFetchFile($filename, $cacheKey, $lastModifiedTime = null) { $retries = 3; - $httpDownloader = $this->httpDownloader; + $httpDownloader = $this->httpDownloader; if ($this->eventDispatcher) { $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename); $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent); - $httpDownloader = $preFileDownloadEvent->getHttpDownloader(); } $options = $lastModifiedTime ? array('http' => array('header' => array('If-Modified-Since: '.$lastModifiedTime))) : array();