1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-11 09:32:55 +00:00

Fire POST_FILE_DOWNLOAD event for metadata fetched by ComposerRepository.

This commit is contained in:
Phéna Proxima 2021-04-08 11:08:13 -04:00
parent de112c519e
commit df0a2cdd0a
2 changed files with 62 additions and 10 deletions

View file

@ -22,6 +22,7 @@ use Composer\Json\JsonFile;
use Composer\Cache;
use Composer\Config;
use Composer\IO\IOInterface;
use Composer\Plugin\PostFileDownloadEvent;
use Composer\Semver\CompilingMatcher;
use Composer\Util\HttpDownloader;
use Composer\Util\Loop;
@ -1110,6 +1111,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
throw new RepositorySecurityException('The contents of '.$filename.' do not match its signature. This could indicate a man-in-the-middle attack or e.g. antivirus software corrupting files. Try running composer again and report this if you think it is a mistake.');
}
if ($this->eventDispatcher) {
$postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, null, $sha256, $filename, $response, 'metadata');
$this->eventDispatcher->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent);
}
$data = $response->decodeJson();
HttpDownloader::outputWarnings($this->io, $this->url, $data);
@ -1188,6 +1194,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return true;
}
if ($this->eventDispatcher) {
$postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, null, null, $filename, $response, 'metadata');
$this->eventDispatcher->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent);
}
$data = $response->decodeJson();
HttpDownloader::outputWarnings($this->io, $this->url, $data);
@ -1258,9 +1269,10 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$url = $this->url;
$cache = $this->cache;
$degradedMode = &$this->degradedMode;
$eventDispatcher = $this->eventDispatcher;
$repo = $this;
$accept = function ($response) use ($io, $url, $filename, $cache, $cacheKey, $repo) {
$accept = function ($response) use ($io, $url, $filename, $cache, $cacheKey, $eventDispatcher, $repo) {
// package not found is acceptable for a v2 protocol repository
if ($response->getStatusCode() === 404) {
$repo->packagesNotFoundCache[$filename] = true;
@ -1275,6 +1287,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return true;
}
if ($eventDispatcher) {
$postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, null, null, $url, $response, 'metadata');
$eventDispatcher->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent);
}
$data = $response->decodeJson();
HttpDownloader::outputWarnings($io, $url, $data);