From 3e2163de5cb0bfe3a70a480eff13d4a0a660c0cd Mon Sep 17 00:00:00 2001 From: Lucas D Hedding Date: Mon, 20 Apr 2020 13:50:42 -0600 Subject: [PATCH 1/2] #8809: expand context for post file download event --- src/Composer/Downloader/FileDownloader.php | 2 +- src/Composer/Plugin/PostFileDownloadEvent.php | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 77a310888..153f11e06 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -159,7 +159,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface } if ($eventDispatcher) { - $postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, $fileName, $checksum, $url['processed']); + $postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, $fileName, $checksum, $url['processed'], $package); $eventDispatcher->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent); } diff --git a/src/Composer/Plugin/PostFileDownloadEvent.php b/src/Composer/Plugin/PostFileDownloadEvent.php index 081e64507..a4bc2ac4a 100644 --- a/src/Composer/Plugin/PostFileDownloadEvent.php +++ b/src/Composer/Plugin/PostFileDownloadEvent.php @@ -13,7 +13,7 @@ namespace Composer\Plugin; use Composer\EventDispatcher\Event; -use Composer\Util\RemoteFilesystem; +use Composer\Package\PackageInterface; /** * The post file download event. @@ -38,6 +38,11 @@ class PostFileDownloadEvent extends Event */ private $url; + /** + * @var \Composer\Package\PackageInterface + */ + private $package; + /** * Constructor. * @@ -45,13 +50,15 @@ class PostFileDownloadEvent extends Event * @param string $fileName The file name * @param string|null $checksum The checksum * @param string $url The processed url + * @param PackageInterface $package The package. */ - public function __construct($name, $fileName, $checksum, $url) + public function __construct($name, $fileName, $checksum, $url, PackageInterface $package) { parent::__construct($name); $this->fileName = $fileName; $this->checksum = $checksum; $this->url = $url; + $this->package = $package; } /** @@ -82,4 +89,14 @@ class PostFileDownloadEvent extends Event return $this->url; } + /** + * Get the package. + * + * @return \Composer\Package\PackageInterface + * The package. + */ + public function getPackage() { + return $this->package; + } + } From 2bf2e9fc603eac654e6e5f647fa6adf9a84f63fd Mon Sep 17 00:00:00 2001 From: Lucas D Hedding Date: Mon, 20 Apr 2020 14:40:25 -0600 Subject: [PATCH 2/2] fix failing tests --- src/Composer/Downloader/FileDownloader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 153f11e06..21a3e858b 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -141,7 +141,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface ->then($accept, $reject); } - return $result->then(function ($result) use ($fileName, $checksum, $url, $eventDispatcher) { + return $result->then(function ($result) use ($fileName, $checksum, $url, $package, $eventDispatcher) { // in case of retry, the first call's Promise chain finally calls this twice at the end, // once with $result being the returned $fileName from $accept, and then once for every // failed request with a null result, which can be skipped.