1
0
Fork 0

Merge pull request #3142 from francoispluchino/plugin-load-only-one-time

Register plugin only one time when it's present in global and project mode
pull/2085/merge
Jordi Boggiano 2014-09-30 15:19:55 +01:00
commit 663cda8827
2 changed files with 23 additions and 0 deletions

View File

@ -37,6 +37,7 @@ class PluginManager
protected $versionParser; protected $versionParser;
protected $plugins = array(); protected $plugins = array();
protected $registeredPlugins = array();
private static $classCounter = 0; private static $classCounter = 0;
@ -195,6 +196,10 @@ class PluginManager
{ {
$oldInstallerPlugin = ($package->getType() === 'composer-installer'); $oldInstallerPlugin = ($package->getType() === 'composer-installer');
if (in_array($package->getName(), $this->registeredPlugins)) {
return;
}
$extra = $package->getExtra(); $extra = $package->getExtra();
if (empty($extra['class'])) { if (empty($extra['class'])) {
throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.'); throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.');
@ -237,6 +242,7 @@ class PluginManager
} else { } else {
$plugin = new $class(); $plugin = new $class();
$this->addPlugin($plugin); $this->addPlugin($plugin);
$this->registeredPlugins[] = $package->getName();
} }
} }
} }

View File

@ -164,4 +164,21 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
$plugins = $this->pm->getPlugins(); $plugins = $this->pm->getPlugins();
$this->assertEquals('installer-v3', $plugins[1]->version); $this->assertEquals('installer-v3', $plugins[1]->version);
} }
public function testRegisterPluginOnlyOneTime()
{
$this->repository
->expects($this->exactly(2))
->method('getPackages')
->will($this->returnValue(array()));
$installer = new PluginInstaller($this->io, $this->composer);
$this->pm->loadInstalledPlugins();
$installer->install($this->repository, $this->packages[0]);
$installer->install($this->repository, clone $this->packages[0]);
$plugins = $this->pm->getPlugins();
$this->assertCount(1, $plugins);
$this->assertEquals('installer-v1', $plugins[0]->version);
}
} }