Implement type and context properties in PreFileDownloadEvent
parent
907367ff43
commit
5c13c97428
|
@ -125,7 +125,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
|
||||||
$url = reset($urls);
|
$url = reset($urls);
|
||||||
|
|
||||||
if ($eventDispatcher) {
|
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);
|
$eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||||
$url['processed'] = $preFileDownloadEvent->getProcessedUrl();
|
$url['processed'] = $preFileDownloadEvent->getProcessedUrl();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,18 +32,32 @@ class PreFileDownloadEvent extends Event
|
||||||
*/
|
*/
|
||||||
private $processedUrl;
|
private $processedUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
private $context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $name The event name
|
* @param string $name The event name
|
||||||
* @param HttpDownloader $httpDownloader
|
* @param HttpDownloader $httpDownloader
|
||||||
* @param string $processedUrl
|
* @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);
|
parent::__construct($name);
|
||||||
$this->httpDownloader = $httpDownloader;
|
$this->httpDownloader = $httpDownloader;
|
||||||
$this->processedUrl = $processedUrl;
|
$this->processedUrl = $processedUrl;
|
||||||
|
$this->type = $type;
|
||||||
|
$this->context = $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,4 +87,25 @@ class PreFileDownloadEvent extends Event
|
||||||
{
|
{
|
||||||
$this->processedUrl = $processedUrl;
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
||||||
while ($retries--) {
|
while ($retries--) {
|
||||||
try {
|
try {
|
||||||
if ($this->eventDispatcher) {
|
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);
|
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||||
$filename = $preFileDownloadEvent->getProcessedUrl();
|
$filename = $preFileDownloadEvent->getProcessedUrl();
|
||||||
}
|
}
|
||||||
|
@ -1100,7 +1100,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
||||||
while ($retries--) {
|
while ($retries--) {
|
||||||
try {
|
try {
|
||||||
if ($this->eventDispatcher) {
|
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);
|
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||||
$filename = $preFileDownloadEvent->getProcessedUrl();
|
$filename = $preFileDownloadEvent->getProcessedUrl();
|
||||||
}
|
}
|
||||||
|
@ -1167,7 +1167,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
||||||
|
|
||||||
$httpDownloader = $this->httpDownloader;
|
$httpDownloader = $this->httpDownloader;
|
||||||
if ($this->eventDispatcher) {
|
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);
|
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||||
$filename = $preFileDownloadEvent->getProcessedUrl();
|
$filename = $preFileDownloadEvent->getProcessedUrl();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue