|
@@ -18,10 +18,11 @@ use Composer\IO\IOInterface;
|
|
|
use Composer\Package\Archiver;
|
|
|
use Composer\Repository\ComposerRepository;
|
|
|
use Composer\Repository\RepositoryManager;
|
|
|
+use Composer\Repository\RepositoryInterface;
|
|
|
use Composer\Util\ProcessExecutor;
|
|
|
use Composer\Util\RemoteFilesystem;
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
|
|
-use Composer\Script\EventDispatcher;
|
|
|
+use Composer\EventDispatcher\EventDispatcher;
|
|
|
use Composer\Autoload\AutoloadGenerator;
|
|
|
use Composer\Package\Version\VersionParser;
|
|
|
|
|
@@ -31,6 +32,7 @@ use Composer\Package\Version\VersionParser;
|
|
|
* @author Ryan Weaver <ryan@knplabs.com>
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
* @author Igor Wiedler <igor@wiedler.ch>
|
|
|
+ * @author Nils Adermann <naderman@naderman.de>
|
|
|
*/
|
|
|
class Factory
|
|
|
{
|
|
@@ -176,11 +178,12 @@ class Factory
|
|
|
* @param IOInterface $io IO instance
|
|
|
* @param array|string|null $localConfig either a configuration array or a filename to read from, if null it will
|
|
|
* read from the default filename
|
|
|
+ * @param bool $disablePlugins Whether plugins should not be loaded
|
|
|
* @throws \InvalidArgumentException
|
|
|
* @throws \UnexpectedValueException
|
|
|
* @return Composer
|
|
|
*/
|
|
|
- public function createComposer(IOInterface $io, $localConfig = null)
|
|
|
+ public function createComposer(IOInterface $io, $localConfig = null, $disablePlugins = false)
|
|
|
{
|
|
|
// load Composer configuration
|
|
|
if (null === $localConfig) {
|
|
@@ -227,9 +230,6 @@ class Factory
|
|
|
$loader = new Package\Loader\RootPackageLoader($rm, $config, $parser, new ProcessExecutor($io));
|
|
|
$package = $loader->load($localConfig);
|
|
|
|
|
|
- // initialize download manager
|
|
|
- $dm = $this->createDownloadManager($io, $config);
|
|
|
-
|
|
|
// initialize installation manager
|
|
|
$im = $this->createInstallationManager();
|
|
|
|
|
@@ -238,20 +238,32 @@ class Factory
|
|
|
$composer->setConfig($config);
|
|
|
$composer->setPackage($package);
|
|
|
$composer->setRepositoryManager($rm);
|
|
|
- $composer->setDownloadManager($dm);
|
|
|
$composer->setInstallationManager($im);
|
|
|
|
|
|
// initialize event dispatcher
|
|
|
$dispatcher = new EventDispatcher($composer, $io);
|
|
|
+
|
|
|
+ // initialize download manager
|
|
|
+ $dm = $this->createDownloadManager($io, $config, $dispatcher);
|
|
|
+
|
|
|
+ $composer->setDownloadManager($dm);
|
|
|
$composer->setEventDispatcher($dispatcher);
|
|
|
|
|
|
// initialize autoload generator
|
|
|
$generator = new AutoloadGenerator($dispatcher);
|
|
|
$composer->setAutoloadGenerator($generator);
|
|
|
|
|
|
+ $globalRepository = $this->createGlobalRepository($config, $vendorDir);
|
|
|
+ $pm = $this->createPluginManager($composer, $io, $globalRepository);
|
|
|
+ $composer->setPluginManager($pm);
|
|
|
+
|
|
|
// add installers to the manager
|
|
|
$this->createDefaultInstallers($im, $composer, $io);
|
|
|
|
|
|
+ if (!$disablePlugins) {
|
|
|
+ $pm->loadInstalledPlugins();
|
|
|
+ }
|
|
|
+
|
|
|
// purge packages if they have been deleted on the filesystem
|
|
|
$this->purgePackages($rm, $im);
|
|
|
|
|
@@ -296,12 +308,31 @@ class Factory
|
|
|
$rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed.json')));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param Config $config
|
|
|
+ * @param string $vendorDir
|
|
|
+ */
|
|
|
+ protected function createGlobalRepository(Config $config, $vendorDir)
|
|
|
+ {
|
|
|
+ if ($config->get('home') == $vendorDir) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $path = $config->get('home').'/vendor/composer/installed.json';
|
|
|
+ if (!file_exists($path)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return new Repository\InstalledFilesystemRepository(new JsonFile($path));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param IO\IOInterface $io
|
|
|
* @param Config $config
|
|
|
+ * @param EventDispatcher $eventDispatcher
|
|
|
* @return Downloader\DownloadManager
|
|
|
*/
|
|
|
- public function createDownloadManager(IOInterface $io, Config $config)
|
|
|
+ public function createDownloadManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
|
|
|
{
|
|
|
$cache = null;
|
|
|
if ($config->get('cache-files-ttl') > 0) {
|
|
@@ -325,10 +356,10 @@ class Factory
|
|
|
$dm->setDownloader('git', new Downloader\GitDownloader($io, $config));
|
|
|
$dm->setDownloader('svn', new Downloader\SvnDownloader($io, $config));
|
|
|
$dm->setDownloader('hg', new Downloader\HgDownloader($io, $config));
|
|
|
- $dm->setDownloader('zip', new Downloader\ZipDownloader($io, $config, $cache));
|
|
|
- $dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $cache));
|
|
|
- $dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $cache));
|
|
|
- $dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $cache));
|
|
|
+ $dm->setDownloader('zip', new Downloader\ZipDownloader($io, $config, $eventDispatcher, $cache));
|
|
|
+ $dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $eventDispatcher, $cache));
|
|
|
+ $dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $eventDispatcher, $cache));
|
|
|
+ $dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $eventDispatcher, $cache));
|
|
|
|
|
|
return $dm;
|
|
|
}
|
|
@@ -353,6 +384,14 @@ class Factory
|
|
|
return $am;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return Plugin\PluginManager
|
|
|
+ */
|
|
|
+ protected function createPluginManager(Composer $composer, IOInterface $io, RepositoryInterface $globalRepository = null)
|
|
|
+ {
|
|
|
+ return new Plugin\PluginManager($composer, $io, $globalRepository);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return Installer\InstallationManager
|
|
|
*/
|
|
@@ -370,7 +409,7 @@ class Factory
|
|
|
{
|
|
|
$im->addInstaller(new Installer\LibraryInstaller($io, $composer, null));
|
|
|
$im->addInstaller(new Installer\PearInstaller($io, $composer, 'pear-library'));
|
|
|
- $im->addInstaller(new Installer\InstallerInstaller($io, $composer));
|
|
|
+ $im->addInstaller(new Installer\PluginInstaller($io, $composer));
|
|
|
$im->addInstaller(new Installer\MetapackageInstaller($io));
|
|
|
}
|
|
|
|
|
@@ -392,12 +431,13 @@ class Factory
|
|
|
* @param IOInterface $io IO instance
|
|
|
* @param mixed $config either a configuration array or a filename to read from, if null it will read from
|
|
|
* the default filename
|
|
|
+ * @param bool $disablePlugins Whether plugins should not be loaded
|
|
|
* @return Composer
|
|
|
*/
|
|
|
- public static function create(IOInterface $io, $config = null)
|
|
|
+ public static function create(IOInterface $io, $config = null, $disablePlugins = false)
|
|
|
{
|
|
|
$factory = new static();
|
|
|
|
|
|
- return $factory->createComposer($io, $config);
|
|
|
+ return $factory->createComposer($io, $config, $disablePlugins);
|
|
|
}
|
|
|
}
|