diff --git a/BaseCommand.php b/BaseCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..dfd7f7b2db1bfd15fbfcb485b8585f21ba76ee1a --- /dev/null +++ b/BaseCommand.php @@ -0,0 +1,32 @@ +<?php + +namespace LakeDrops\Component\Composer; + +use Composer\Command\BaseCommand as ComposerBaseCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Class BaseCommand. + * + * @package LakeDrops\Component\Composer + */ +abstract class BaseCommand extends ComposerBaseCommand implements BaseCommandInterface { + + /** + * The handler object to do the real work then. + * + * @var \LakeDrops\Component\Composer\BaseHandlerInterface + */ + protected $handler; + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $class = $this->getHandlerClass(); + $this->handler = new $class($this->getComposer(), $this->getIO()); + $this->handler->setInput($input); + } + +} diff --git a/BaseCommandInterface.php b/BaseCommandInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..62ffdde0f60cb003f315436a8e6943d3f59930a4 --- /dev/null +++ b/BaseCommandInterface.php @@ -0,0 +1,17 @@ +<?php + +namespace LakeDrops\Component\Composer; + +/** + * Interface for BaseCommand. + * + * @package LakeDrops\Component\Composer + */ +interface BaseCommandInterface { + + /** + * @return \LakeDrops\Component\Composer\BaseHandlerInterface + */ + public function getHandlerClass(); + +} diff --git a/BaseHandler.php b/BaseHandler.php index 3cd0de21e34ec8dbc52d0f377a187f4f09c37a27..d74e59bf57df35c722c14e8bcfca47b2f5b89603 100644 --- a/BaseHandler.php +++ b/BaseHandler.php @@ -4,6 +4,8 @@ namespace LakeDrops\Component\Composer; use Composer\Composer; use Composer\IO\IOInterface; +use Composer\Script\Event; +use Symfony\Component\Console\Input\InputInterface; /** * Class BaseHandler. @@ -26,6 +28,18 @@ abstract class BaseHandler implements BaseHandlerInterface { */ protected $io; + /** + * @var \Symfony\Component\Console\Input\InputInterface + */ + protected $input; + + /** + * The event that triggered the action. + * + * @var \Composer\Script\Event + */ + protected $event; + /** * The Drupal core package. * @@ -46,6 +60,22 @@ abstract class BaseHandler implements BaseHandlerInterface { $this->io = $io; } + /** + * {@inheritdoc} + */ + public function setEvent(Event $event) { + $this->event = $event; + return $this; + } + + /** + * {@inheritdoc} + */ + public function setInput(InputInterface $input) { + $this->input = $input; + return $this; + } + /** * {@inheritdoc} */ @@ -63,6 +93,19 @@ abstract class BaseHandler implements BaseHandlerInterface { return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*'); } + /** + * {@inheritdoc} + */ + public function isDevMode() { + if ($this->event !== NULL) { + return $this->event->isDevMode(); + } + if ($this->input !== NULL) { + return !$this->input->hasOption('no-dev'); + } + return FALSE; + } + /** * {@inheritdoc} */ diff --git a/BaseHandlerInterface.php b/BaseHandlerInterface.php index 8ea968aeabaaa928dc59a46919a94fd02aa7cb33..372847b9487dbcb97ab58d3d073a531e58e2ae74 100644 --- a/BaseHandlerInterface.php +++ b/BaseHandlerInterface.php @@ -2,6 +2,9 @@ namespace LakeDrops\Component\Composer; +use Composer\Script\Event; +use Symfony\Component\Console\Input\InputInterface; + /** * Interface for BaseHandler. * @@ -9,6 +12,16 @@ namespace LakeDrops\Component\Composer; */ interface BaseHandlerInterface { + /** + * @param \Composer\Script\Event $event + */ + public function setEvent(Event $event); + + /** + * @param \Symfony\Component\Console\Input\InputInterface $input + */ + public function setInput(InputInterface $input); + /** * Look up the Drupal core package object. * @@ -28,6 +41,11 @@ interface BaseHandlerInterface { */ public function getPackage($name); + /** + * @return bool + */ + public function isDevMode(); + /** * Determine if the current process runs in a CI/CD context. *