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