mirror of
https://github.com/composer/composer
synced 2025-05-10 17:12:51 +00:00
Merge pull request #9822 from phenaproxima/post-file-download
Fire POST_FILE_DOWNLOAD event for metadata fetched by ComposerRepository
This commit is contained in:
commit
d75d79b452
6 changed files with 78 additions and 16 deletions
|
@ -24,6 +24,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;
|
||||
|
@ -1088,7 +1089,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
while ($retries--) {
|
||||
try {
|
||||
if ($this->eventDispatcher) {
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata');
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata', array('repository' => $this));
|
||||
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||
$filename = $preFileDownloadEvent->getProcessedUrl();
|
||||
}
|
||||
|
@ -1113,6 +1114,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, 'metadata', array('response' => $response, 'repository' => $this));
|
||||
$this->eventDispatcher->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent);
|
||||
}
|
||||
|
||||
$data = $response->decodeJson();
|
||||
HttpDownloader::outputWarnings($this->io, $this->url, $data);
|
||||
|
||||
|
@ -1175,7 +1181,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
while ($retries--) {
|
||||
try {
|
||||
if ($this->eventDispatcher) {
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata');
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata', array('repository' => $this));
|
||||
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||
$filename = $preFileDownloadEvent->getProcessedUrl();
|
||||
}
|
||||
|
@ -1191,6 +1197,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
return true;
|
||||
}
|
||||
|
||||
if ($this->eventDispatcher) {
|
||||
$postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, null, null, $filename, 'metadata', array('response' => $response, 'repository' => $this));
|
||||
$this->eventDispatcher->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent);
|
||||
}
|
||||
|
||||
$data = $response->decodeJson();
|
||||
HttpDownloader::outputWarnings($this->io, $this->url, $data);
|
||||
|
||||
|
@ -1244,7 +1255,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
|
||||
$httpDownloader = $this->httpDownloader;
|
||||
if ($this->eventDispatcher) {
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata');
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata', array('repository' => $this));
|
||||
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||
$filename = $preFileDownloadEvent->getProcessedUrl();
|
||||
}
|
||||
|
@ -1261,9 +1272,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;
|
||||
|
@ -1278,6 +1290,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
return true;
|
||||
}
|
||||
|
||||
if ($eventDispatcher) {
|
||||
$postFileDownloadEvent = new PostFileDownloadEvent(PluginEvents::POST_FILE_DOWNLOAD, null, null, $url, 'metadata', array('response' => $response, 'repository' => $repo));
|
||||
$eventDispatcher->dispatch($postFileDownloadEvent->getName(), $postFileDownloadEvent);
|
||||
}
|
||||
|
||||
$data = $response->decodeJson();
|
||||
HttpDownloader::outputWarnings($io, $url, $data);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue