Add preFileDownload event on package.json fetch
parent
a1e4ca4f9b
commit
fbadc19bf6
|
@ -220,8 +220,15 @@ class Factory
|
||||||
// setup process timeout
|
// setup process timeout
|
||||||
ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
|
ProcessExecutor::setTimeout((int) $config->get('process-timeout'));
|
||||||
|
|
||||||
|
// initialize composer
|
||||||
|
$composer = new Composer();
|
||||||
|
$composer->setConfig($config);
|
||||||
|
|
||||||
|
// initialize event dispatcher
|
||||||
|
$dispatcher = new EventDispatcher($composer, $io);
|
||||||
|
|
||||||
// initialize repository manager
|
// initialize repository manager
|
||||||
$rm = $this->createRepositoryManager($io, $config);
|
$rm = $this->createRepositoryManager($io, $config, $dispatcher);
|
||||||
|
|
||||||
// load local repository
|
// load local repository
|
||||||
$this->addLocalRepository($rm, $vendorDir);
|
$this->addLocalRepository($rm, $vendorDir);
|
||||||
|
@ -234,16 +241,11 @@ class Factory
|
||||||
// initialize installation manager
|
// initialize installation manager
|
||||||
$im = $this->createInstallationManager();
|
$im = $this->createInstallationManager();
|
||||||
|
|
||||||
// initialize composer
|
// Composer composition
|
||||||
$composer = new Composer();
|
|
||||||
$composer->setConfig($config);
|
|
||||||
$composer->setPackage($package);
|
$composer->setPackage($package);
|
||||||
$composer->setRepositoryManager($rm);
|
$composer->setRepositoryManager($rm);
|
||||||
$composer->setInstallationManager($im);
|
$composer->setInstallationManager($im);
|
||||||
|
|
||||||
// initialize event dispatcher
|
|
||||||
$dispatcher = new EventDispatcher($composer, $io);
|
|
||||||
|
|
||||||
// initialize download manager
|
// initialize download manager
|
||||||
$dm = $this->createDownloadManager($io, $config, $dispatcher);
|
$dm = $this->createDownloadManager($io, $config, $dispatcher);
|
||||||
|
|
||||||
|
@ -285,9 +287,9 @@ class Factory
|
||||||
* @param Config $config
|
* @param Config $config
|
||||||
* @return Repository\RepositoryManager
|
* @return Repository\RepositoryManager
|
||||||
*/
|
*/
|
||||||
protected function createRepositoryManager(IOInterface $io, Config $config)
|
protected function createRepositoryManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
|
||||||
{
|
{
|
||||||
$rm = new RepositoryManager($io, $config);
|
$rm = new RepositoryManager($io, $config, $eventDispatcher);
|
||||||
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
|
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
|
||||||
$rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
|
$rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
|
||||||
$rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
|
$rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
|
||||||
|
|
|
@ -22,6 +22,9 @@ use Composer\Cache;
|
||||||
use Composer\Config;
|
use Composer\Config;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Util\RemoteFilesystem;
|
use Composer\Util\RemoteFilesystem;
|
||||||
|
use Composer\Plugin\PluginEvents;
|
||||||
|
use Composer\Plugin\PreFileDownloadEvent;
|
||||||
|
use Composer\EventDispatcher\EventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
@ -45,12 +48,13 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
|
||||||
protected $loader;
|
protected $loader;
|
||||||
protected $rootAliases;
|
protected $rootAliases;
|
||||||
protected $allowSslDowngrade = false;
|
protected $allowSslDowngrade = false;
|
||||||
|
protected $eventDispatcher;
|
||||||
private $rawData;
|
private $rawData;
|
||||||
private $minimalPackages;
|
private $minimalPackages;
|
||||||
private $degradedMode = false;
|
private $degradedMode = false;
|
||||||
private $rootData;
|
private $rootData;
|
||||||
|
|
||||||
public function __construct(array $repoConfig, IOInterface $io, Config $config)
|
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
|
||||||
{
|
{
|
||||||
if (!preg_match('{^[\w.]+\??://}', $repoConfig['url'])) {
|
if (!preg_match('{^[\w.]+\??://}', $repoConfig['url'])) {
|
||||||
// assume http as the default protocol
|
// assume http as the default protocol
|
||||||
|
@ -82,6 +86,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
|
||||||
$this->cache = new Cache($io, $config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$');
|
$this->cache = new Cache($io, $config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$');
|
||||||
$this->loader = new ArrayLoader();
|
$this->loader = new ArrayLoader();
|
||||||
$this->rfs = new RemoteFilesystem($this->io, $this->options);
|
$this->rfs = new RemoteFilesystem($this->io, $this->options);
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRootAliases(array $rootAliases)
|
public function setRootAliases(array $rootAliases)
|
||||||
|
@ -538,7 +543,11 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
|
||||||
$retries = 3;
|
$retries = 3;
|
||||||
while ($retries--) {
|
while ($retries--) {
|
||||||
try {
|
try {
|
||||||
$json = $this->rfs->getContents($filename, $filename, false);
|
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->rfs, $filename);
|
||||||
|
if ($this->eventDispatcher) {
|
||||||
|
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||||
|
}
|
||||||
|
$json = $preFileDownloadEvent->getRemoteFilesystem()->getContents($filename, $filename, false);
|
||||||
if ($sha256 && $sha256 !== hash('sha256', $json)) {
|
if ($sha256 && $sha256 !== hash('sha256', $json)) {
|
||||||
if ($retries) {
|
if ($retries) {
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer\Repository;
|
||||||
|
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Config;
|
use Composer\Config;
|
||||||
|
use Composer\EventDispatcher\EventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repositories manager.
|
* Repositories manager.
|
||||||
|
@ -29,11 +30,13 @@ class RepositoryManager
|
||||||
private $repositoryClasses = array();
|
private $repositoryClasses = array();
|
||||||
private $io;
|
private $io;
|
||||||
private $config;
|
private $config;
|
||||||
|
private $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(IOInterface $io, Config $config)
|
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
|
||||||
{
|
{
|
||||||
$this->io = $io;
|
$this->io = $io;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,7 +101,7 @@ class RepositoryManager
|
||||||
|
|
||||||
$class = $this->repositoryClasses[$type];
|
$class = $this->repositoryClasses[$type];
|
||||||
|
|
||||||
return new $class($config, $this->io, $this->config);
|
return new $class($config, $this->io, $this->config, $this->eventDispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue