Skip to content
Snippets Groups Projects
Commit 957fb15a authored by jurgenhaas's avatar jurgenhaas
Browse files

Implement support for Composer commands

parent afa504b9
No related branches found
No related tags found
No related merge requests found
<?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);
}
}
<?php
namespace LakeDrops\Component\Composer;
/**
* Interface for BaseCommand.
*
* @package LakeDrops\Component\Composer
*/
interface BaseCommandInterface {
/**
* @return \LakeDrops\Component\Composer\BaseHandlerInterface
*/
public function getHandlerClass();
}
......@@ -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}
*/
......
......@@ -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.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment