PluginManager refactoring, fixes #3550
parent
e1921ac962
commit
0627d846a5
|
@ -177,7 +177,7 @@ class Application extends BaseApplication
|
|||
public function renderException($exception, $output)
|
||||
{
|
||||
try {
|
||||
$composer = $this->getComposer(false);
|
||||
$composer = $this->getComposer(false, true);
|
||||
if ($composer) {
|
||||
$config = $composer->getConfig();
|
||||
|
||||
|
|
|
@ -283,18 +283,19 @@ class Factory
|
|||
// add installers to the manager (must happen after download manager is created since they read it out of $composer)
|
||||
$this->createDefaultInstallers($im, $composer, $io);
|
||||
|
||||
$globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins);
|
||||
$globalRepository = $globalComposer ? $globalComposer->getRepositoryManager()->getLocalRepository() : null;
|
||||
$pm = $this->createPluginManager($composer, $io, $globalRepository);
|
||||
$composer->setPluginManager($pm);
|
||||
|
||||
// purge packages if they have been deleted on the filesystem
|
||||
if ($rm->getLocalRepository()) {
|
||||
$this->purgePackages($rm->getLocalRepository(), $im);
|
||||
}
|
||||
|
||||
if (!$disablePlugins) {
|
||||
$pm->loadInstalledPlugins();
|
||||
if ($fullLoad) {
|
||||
$globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins);
|
||||
$pm = $this->createPluginManager($io, $composer, $globalComposer);
|
||||
$composer->setPluginManager($pm);
|
||||
|
||||
if (!$disablePlugins) {
|
||||
$pm->loadInstalledPlugins();
|
||||
}
|
||||
}
|
||||
|
||||
// init locker if possible
|
||||
|
@ -424,14 +425,14 @@ class Factory
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Composer $composer
|
||||
* @param IOInterface $io
|
||||
* @param RepositoryInterface $globalRepository
|
||||
* @param Composer $composer
|
||||
* @param Composer $globalComposer
|
||||
* @return Plugin\PluginManager
|
||||
*/
|
||||
protected function createPluginManager(Composer $composer, IOInterface $io, RepositoryInterface $globalRepository = null)
|
||||
protected function createPluginManager(IOInterface $io, Composer $composer, Composer $globalComposer = null)
|
||||
{
|
||||
return new Plugin\PluginManager($composer, $io, $globalRepository);
|
||||
return new Plugin\PluginManager($io, $composer, $globalComposer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,12 +28,13 @@ use Composer\DependencyResolver\Pool;
|
|||
* Plugin manager
|
||||
*
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class PluginManager
|
||||
{
|
||||
protected $composer;
|
||||
protected $io;
|
||||
protected $globalRepository;
|
||||
protected $globalComposer;
|
||||
protected $versionParser;
|
||||
|
||||
protected $plugins = array();
|
||||
|
@ -44,15 +45,15 @@ class PluginManager
|
|||
/**
|
||||
* Initializes plugin manager
|
||||
*
|
||||
* @param Composer $composer
|
||||
* @param IOInterface $io
|
||||
* @param RepositoryInterface $globalRepository
|
||||
* @param Composer $composer
|
||||
* @param Composer $globalComposer
|
||||
*/
|
||||
public function __construct(Composer $composer, IOInterface $io, RepositoryInterface $globalRepository = null)
|
||||
public function __construct(IOInterface $io, Composer $composer, Composer $globalComposer = null)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->io = $io;
|
||||
$this->globalRepository = $globalRepository;
|
||||
$this->composer = $composer;
|
||||
$this->globalComposer = $globalComposer;
|
||||
$this->versionParser = new VersionParser();
|
||||
}
|
||||
|
||||
|
@ -62,12 +63,12 @@ class PluginManager
|
|||
public function loadInstalledPlugins()
|
||||
{
|
||||
$repo = $this->composer->getRepositoryManager()->getLocalRepository();
|
||||
|
||||
$globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
|
||||
if ($repo) {
|
||||
$this->loadRepository($repo);
|
||||
}
|
||||
if ($this->globalRepository) {
|
||||
$this->loadRepository($this->globalRepository);
|
||||
if ($globalRepo) {
|
||||
$this->loadRepository($globalRepo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,11 +207,13 @@ class PluginManager
|
|||
}
|
||||
$classes = is_array($extra['class']) ? $extra['class'] : array($extra['class']);
|
||||
|
||||
$pool = new Pool('dev');
|
||||
$localRepo = $this->composer->getRepositoryManager()->getLocalRepository();
|
||||
$globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
|
||||
|
||||
$pool = new Pool('dev');
|
||||
$pool->addRepository($localRepo);
|
||||
if ($this->globalRepository) {
|
||||
$pool->addRepository($this->globalRepository);
|
||||
if ($globalRepo) {
|
||||
$pool->addRepository($globalRepo);
|
||||
}
|
||||
|
||||
$autoloadPackages = array($package->getName() => $package);
|
||||
|
@ -219,7 +222,7 @@ class PluginManager
|
|||
$generator = $this->composer->getAutoloadGenerator();
|
||||
$autoloads = array();
|
||||
foreach ($autoloadPackages as $autoloadPackage) {
|
||||
$downloadPath = $this->getInstallPath($autoloadPackage, ($this->globalRepository && $this->globalRepository->hasPackage($autoloadPackage)));
|
||||
$downloadPath = $this->getInstallPath($autoloadPackage, ($globalRepo && $globalRepo->hasPackage($autoloadPackage)));
|
||||
$autoloads[] = array($autoloadPackage, $downloadPath);
|
||||
}
|
||||
|
||||
|
@ -261,9 +264,6 @@ class PluginManager
|
|||
return $this->composer->getInstallationManager()->getInstallPath($package);
|
||||
}
|
||||
|
||||
$targetDir = $package->getTargetDir();
|
||||
$vendorDir = $this->composer->getConfig()->get('home').'/vendor';
|
||||
|
||||
return ($vendorDir ? $vendorDir.'/' : '').$package->getPrettyName().($targetDir ? '/'.$targetDir : '');
|
||||
return $this->globalComposer->getInstallationManager()->getInstallPath($package);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->composer->setInstallationManager($im);
|
||||
$this->composer->setAutoloadGenerator($this->autoloadGenerator);
|
||||
|
||||
$this->pm = new PluginManager($this->composer, $this->io);
|
||||
$this->pm = new PluginManager($this->io, $this->composer);
|
||||
$this->composer->setPluginManager($this->pm);
|
||||
|
||||
$config->merge(array(
|
||||
|
|
Loading…
Reference in New Issue