diff --git a/composer.json b/composer.json index 4d03844..937da15 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ } }, "require": { + "php": ">=5.6", "composer-plugin-api": "^1.0", "symfony/console": "^2.7 || ^3.0 || ^4.0", "symfony/filesystem": "^2.5 || ^3.0 || ^4.0", diff --git a/src/Composer/StudioPlugin.php b/src/Composer/StudioPlugin.php index c1b3b41..a437e4b 100644 --- a/src/Composer/StudioPlugin.php +++ b/src/Composer/StudioPlugin.php @@ -5,7 +5,9 @@ use Composer\Composer; use Composer\EventDispatcher\EventSubscriberInterface; use Composer\IO\IOInterface; +use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginInterface; +use Composer\Plugin\PreCommandRunEvent; use Composer\Repository\PathRepository; use Composer\Script\ScriptEvents; use Studio\Config\Config; @@ -23,6 +25,16 @@ class StudioPlugin implements PluginInterface, EventSubscriberInterface */ protected $io; + /** + * @var array + */ + const PLUGGED_COMMANDS = [ + 'create-project', + 'install', + 'update', + 'require' + ] ; + public function activate(Composer $composer, IOInterface $io) { $this->composer = $composer; @@ -32,8 +44,7 @@ public function activate(Composer $composer, IOInterface $io) public static function getSubscribedEvents() { return [ - ScriptEvents::PRE_INSTALL_CMD => 'registerStudioPackages', - ScriptEvents::PRE_UPDATE_CMD => 'registerStudioPackages', + PluginEvents::PRE_COMMAND_RUN => 'registerStudioPackages', ]; } @@ -43,8 +54,12 @@ public static function getSubscribedEvents() * This function configures Composer to treat all Studio-managed paths as local path repositories, so that packages * therein will be symlinked directly. */ - public function registerStudioPackages() + public function registerStudioPackages(PreCommandRunEvent $event) { + if (! in_array($event->getCommand(), static::PLUGGED_COMMANDS)) { + return; + } + $repoManager = $this->composer->getRepositoryManager(); $composerConfig = $this->composer->getConfig();