1
0
Fork 0

Make composer/io part of the activate plugin API rather than constructor args

pull/2179/head
Nils Adermann 2013-08-15 16:58:48 +02:00
parent b83535d2d9
commit b9c5758670
8 changed files with 22 additions and 13 deletions

View File

@ -13,6 +13,7 @@
namespace Composer\Plugin;
use Composer\Composer;
use Composer\IO\IOInterface;
/**
* Plugin interface
@ -23,6 +24,9 @@ interface PluginInterface
{
/**
* Apply plugin modifications to composer
*
* @param Composer $composer
* @param IOInterface $io
*/
public function activate();
public function activate(Composer $composer, IOInterface $io);
}

View File

@ -66,7 +66,7 @@ class PluginManager
public function addPlugin(PluginInterface $plugin)
{
$this->plugins[] = $plugin;
$plugin->activate();
$plugin->activate($this->composer, $this->io);
if ($plugin instanceof EventSubscriberInterface) {
$this->composer->getEventDispatcher()->addSubscriber($plugin);
@ -139,11 +139,11 @@ class PluginManager
self::$classCounter++;
}
$plugin = new $class($this->composer, $this->io);
if ($oldInstallerPlugin) {
$installer = new $class($this->composer, $this->io);
$this->composer->getInstallationManager()->addInstaller($installer);
} else {
$plugin = new $class();
$this->addPlugin($plugin);
}
}

View File

@ -3,13 +3,14 @@
namespace Installer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class Plugin implements PluginInterface
{
public $version = 'installer-v1';
public function activate()
public function activate(Composer $composer, IOInterface $io)
{
}
}

View File

@ -3,13 +3,14 @@
namespace Installer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class Plugin2 implements PluginInterface
{
public $version = 'installer-v2';
public function activate()
public function activate(Composer $composer, IOInterface $io)
{
}
}

View File

@ -3,13 +3,14 @@
namespace Installer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class Plugin2 implements PluginInterface
{
public $version = 'installer-v3';
public function activate()
public function activate(Composer $composer, IOInterface $io)
{
}
}

View File

@ -3,6 +3,7 @@
namespace Installer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class Plugin1 implements PluginInterface
@ -10,7 +11,7 @@ class Plugin1 implements PluginInterface
public $name = 'plugin1';
public $version = 'installer-v4';
public function activate()
public function activate(Composer $composer, IOInterface $io)
{
}
}

View File

@ -3,6 +3,7 @@
namespace Installer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class Plugin2 implements PluginInterface
@ -10,7 +11,7 @@ class Plugin2 implements PluginInterface
public $name = 'plugin2';
public $version = 'installer-v4';
public function activate()
public function activate(Composer $composer, IOInterface $io)
{
}
}

View File

@ -77,7 +77,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
public function testInstallNewPlugin()
{
$this->repository
->expects($this->once())
->expects($this->exactly(2))
->method('getPackages')
->will($this->returnValue(array()));
$installer = new PluginInstaller($this->io, $this->composer);
@ -92,7 +92,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
public function testInstallMultiplePlugins()
{
$this->repository
->expects($this->once())
->expects($this->exactly(2))
->method('getPackages')
->will($this->returnValue(array()));
$installer = new PluginInstaller($this->io, $this->composer);
@ -110,7 +110,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
public function testUpgradeWithNewClassName()
{
$this->repository
->expects($this->once())
->expects($this->exactly(3))
->method('getPackages')
->will($this->returnValue(array($this->packages[0])));
$this->repository
@ -129,7 +129,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
public function testUpgradeWithSameClassName()
{
$this->repository
->expects($this->once())
->expects($this->exactly(3))
->method('getPackages')
->will($this->returnValue(array($this->packages[1])));
$this->repository