Make composer/io part of the activate plugin API rather than constructor args
parent
b83535d2d9
commit
b9c5758670
|
@ -13,6 +13,7 @@
|
||||||
namespace Composer\Plugin;
|
namespace Composer\Plugin;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin interface
|
* Plugin interface
|
||||||
|
@ -23,6 +24,9 @@ interface PluginInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Apply plugin modifications to composer
|
* Apply plugin modifications to composer
|
||||||
|
*
|
||||||
|
* @param Composer $composer
|
||||||
|
* @param IOInterface $io
|
||||||
*/
|
*/
|
||||||
public function activate();
|
public function activate(Composer $composer, IOInterface $io);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ class PluginManager
|
||||||
public function addPlugin(PluginInterface $plugin)
|
public function addPlugin(PluginInterface $plugin)
|
||||||
{
|
{
|
||||||
$this->plugins[] = $plugin;
|
$this->plugins[] = $plugin;
|
||||||
$plugin->activate();
|
$plugin->activate($this->composer, $this->io);
|
||||||
|
|
||||||
if ($plugin instanceof EventSubscriberInterface) {
|
if ($plugin instanceof EventSubscriberInterface) {
|
||||||
$this->composer->getEventDispatcher()->addSubscriber($plugin);
|
$this->composer->getEventDispatcher()->addSubscriber($plugin);
|
||||||
|
@ -139,11 +139,11 @@ class PluginManager
|
||||||
self::$classCounter++;
|
self::$classCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugin = new $class($this->composer, $this->io);
|
|
||||||
|
|
||||||
if ($oldInstallerPlugin) {
|
if ($oldInstallerPlugin) {
|
||||||
|
$installer = new $class($this->composer, $this->io);
|
||||||
$this->composer->getInstallationManager()->addInstaller($installer);
|
$this->composer->getInstallationManager()->addInstaller($installer);
|
||||||
} else {
|
} else {
|
||||||
|
$plugin = new $class();
|
||||||
$this->addPlugin($plugin);
|
$this->addPlugin($plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
namespace Installer;
|
namespace Installer;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
|
|
||||||
class Plugin implements PluginInterface
|
class Plugin implements PluginInterface
|
||||||
{
|
{
|
||||||
public $version = 'installer-v1';
|
public $version = 'installer-v1';
|
||||||
|
|
||||||
public function activate()
|
public function activate(Composer $composer, IOInterface $io)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
namespace Installer;
|
namespace Installer;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
|
|
||||||
class Plugin2 implements PluginInterface
|
class Plugin2 implements PluginInterface
|
||||||
{
|
{
|
||||||
public $version = 'installer-v2';
|
public $version = 'installer-v2';
|
||||||
|
|
||||||
public function activate()
|
public function activate(Composer $composer, IOInterface $io)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
namespace Installer;
|
namespace Installer;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
|
|
||||||
class Plugin2 implements PluginInterface
|
class Plugin2 implements PluginInterface
|
||||||
{
|
{
|
||||||
public $version = 'installer-v3';
|
public $version = 'installer-v3';
|
||||||
|
|
||||||
public function activate()
|
public function activate(Composer $composer, IOInterface $io)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Installer;
|
namespace Installer;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
|
|
||||||
class Plugin1 implements PluginInterface
|
class Plugin1 implements PluginInterface
|
||||||
|
@ -10,7 +11,7 @@ class Plugin1 implements PluginInterface
|
||||||
public $name = 'plugin1';
|
public $name = 'plugin1';
|
||||||
public $version = 'installer-v4';
|
public $version = 'installer-v4';
|
||||||
|
|
||||||
public function activate()
|
public function activate(Composer $composer, IOInterface $io)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Installer;
|
namespace Installer;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Plugin\PluginInterface;
|
use Composer\Plugin\PluginInterface;
|
||||||
|
|
||||||
class Plugin2 implements PluginInterface
|
class Plugin2 implements PluginInterface
|
||||||
|
@ -10,7 +11,7 @@ class Plugin2 implements PluginInterface
|
||||||
public $name = 'plugin2';
|
public $name = 'plugin2';
|
||||||
public $version = 'installer-v4';
|
public $version = 'installer-v4';
|
||||||
|
|
||||||
public function activate()
|
public function activate(Composer $composer, IOInterface $io)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testInstallNewPlugin()
|
public function testInstallNewPlugin()
|
||||||
{
|
{
|
||||||
$this->repository
|
$this->repository
|
||||||
->expects($this->once())
|
->expects($this->exactly(2))
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
$installer = new PluginInstaller($this->io, $this->composer);
|
$installer = new PluginInstaller($this->io, $this->composer);
|
||||||
|
@ -92,7 +92,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testInstallMultiplePlugins()
|
public function testInstallMultiplePlugins()
|
||||||
{
|
{
|
||||||
$this->repository
|
$this->repository
|
||||||
->expects($this->once())
|
->expects($this->exactly(2))
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
$installer = new PluginInstaller($this->io, $this->composer);
|
$installer = new PluginInstaller($this->io, $this->composer);
|
||||||
|
@ -110,7 +110,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testUpgradeWithNewClassName()
|
public function testUpgradeWithNewClassName()
|
||||||
{
|
{
|
||||||
$this->repository
|
$this->repository
|
||||||
->expects($this->once())
|
->expects($this->exactly(3))
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue(array($this->packages[0])));
|
->will($this->returnValue(array($this->packages[0])));
|
||||||
$this->repository
|
$this->repository
|
||||||
|
@ -129,7 +129,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testUpgradeWithSameClassName()
|
public function testUpgradeWithSameClassName()
|
||||||
{
|
{
|
||||||
$this->repository
|
$this->repository
|
||||||
->expects($this->once())
|
->expects($this->exactly(3))
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue(array($this->packages[1])));
|
->will($this->returnValue(array($this->packages[1])));
|
||||||
$this->repository
|
$this->repository
|
||||||
|
|
Loading…
Reference in New Issue