Merge pull request #8975 from ffraenz/pr
Composer 2: Allow plugins to override the URL before triggering the downloadpull/8986/head
commit
0d369c87bc
|
@ -131,8 +131,9 @@ 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();
|
||||
}
|
||||
|
||||
$checksum = $package->getDistSha1Checksum();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,7 +69,7 @@ class PreFileDownloadEvent extends Event
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieves the processed URL this remote filesystem will be used for
|
||||
* Retrieves the processed URL that will be downloaded
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -63,4 +77,35 @@ class PreFileDownloadEvent extends Event
|
|||
{
|
||||
return $this->processedUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the processed URL that will be downloaded
|
||||
*
|
||||
* @param string $processedUrl New processed URL
|
||||
*/
|
||||
public function setProcessedUrl($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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1014,8 +1014,9 @@ 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();
|
||||
}
|
||||
|
||||
$response = $this->httpDownloader->get($filename, $this->options);
|
||||
|
@ -1100,8 +1101,9 @@ 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();
|
||||
}
|
||||
|
||||
$options = $this->options;
|
||||
|
@ -1166,8 +1168,9 @@ 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();
|
||||
}
|
||||
|
||||
$options = $lastModifiedTime ? array('http' => array('header' => array('If-Modified-Since: '.$lastModifiedTime))) : array();
|
||||
|
|
Loading…
Reference in New Issue