1
0
Fork 0

Implement type and context properties in PreFileDownloadEvent

pull/8975/head
Fränz Friederes 2020-06-15 21:43:41 +02:00
parent 907367ff43
commit 5c13c97428
No known key found for this signature in database
GPG Key ID: 583D205C93C01BC0
3 changed files with 43 additions and 8 deletions

View File

@ -125,7 +125,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$url = reset($urls);
if ($eventDispatcher) {
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $httpDownloader, $url['processed']);
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $httpDownloader, $url['processed'], 'package', $package);
$eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
$url['processed'] = $preFileDownloadEvent->getProcessedUrl();
}

View File

@ -32,18 +32,32 @@ class PreFileDownloadEvent extends Event
*/
private $processedUrl;
/**
* @var string
*/
private $type;
/**
* @var mixed
*/
private $context;
/**
* Constructor.
*
* @param string $name The event name
* @param HttpDownloader $httpDownloader
* @param string $processedUrl
* @param string $name The event name
* @param HttpDownloader $httpDownloader
* @param string $processedUrl
* @param string $type
* @param mixed $context
*/
public function __construct($name, HttpDownloader $httpDownloader, $processedUrl)
public function __construct($name, HttpDownloader $httpDownloader, $processedUrl, $type, $context = null)
{
parent::__construct($name);
$this->httpDownloader = $httpDownloader;
$this->processedUrl = $processedUrl;
$this->type = $type;
$this->context = $context;
}
/**
@ -73,4 +87,25 @@ class PreFileDownloadEvent extends Event
{
$this->processedUrl = $processedUrl;
}
/**
* Returns the type of this download (package, metadata)
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Returns the context of this download, if any.
* If this download is of type package, the package object is returned.
*
* @return mixed
*/
public function getContext()
{
return $this->context;
}
}

View File

@ -1013,7 +1013,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
while ($retries--) {
try {
if ($this->eventDispatcher) {
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata');
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
$filename = $preFileDownloadEvent->getProcessedUrl();
}
@ -1100,7 +1100,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
while ($retries--) {
try {
if ($this->eventDispatcher) {
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata');
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
$filename = $preFileDownloadEvent->getProcessedUrl();
}
@ -1167,7 +1167,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$httpDownloader = $this->httpDownloader;
if ($this->eventDispatcher) {
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata');
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
$filename = $preFileDownloadEvent->getProcessedUrl();
}