diff --git a/composer.json b/composer.json index 4da83c158de81be559812b8c4cd5b4e1ad94fbdb..5f21f31adbf59a0d03190a4d092353e9e4ffe686 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require": { "php": ">=5.6", "composer-plugin-api": "^1.0.0", - "lakedrops/composer-scripts": "^1.0.0", + "lakedrops/composer-scripts": "^1.1.0", "lakedrops/docker-traefik": "^1.1.0", "lakedrops/dotenv": "^1.0.0", "twig/twig": "^1.23.1" diff --git a/src/Handler.php b/src/Handler.php index d6c8fd6a794a0755354e431b983e9b3d4ae5375f..dcb870ba150fa973dd5582c64f48bb5dae27ff69 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -2,9 +2,8 @@ namespace LakeDrops\Docker4Drupal; -use Composer\Composer; -use Composer\IO\IOInterface; use Composer\Script\Event; +use LakeDrops\Component\Composer\BaseHandler; use LakeDrops\Component\Dotenv\Dotenv; use LakeDrops\DockerTraefik\Traefik; use Symfony\Component\Filesystem\Filesystem; @@ -15,67 +14,7 @@ use Symfony\Component\Yaml\Yaml; * * @package LakeDrops\Docker4Drupal */ -class Handler { - - /** - * The composer object of this session. - * - * @var \Composer\Composer - */ - protected $composer; - - /** - * The input-output object of the composer session. - * - * @var \Composer\IO\IOInterface - */ - protected $io; - - /** - * The Drupal core package. - * - * @var \Composer\Package\PackageInterface - */ - protected $drupalCorePackage; - - /** - * Handler constructor. - * - * @param \Composer\Composer $composer - * The composer object of this session. - * @param \Composer\IO\IOInterface $io - * The input-output object of the composer session. - */ - public function __construct(Composer $composer, IOInterface $io) { - $this->composer = $composer; - $this->io = $io; - } - - /** - * Look up the Drupal core package object. - * - * @return \Composer\Package\PackageInterface - * The Drupal core package. - */ - protected function getDrupalCorePackage() { - if (!isset($this->drupalCorePackage)) { - $this->drupalCorePackage = $this->getPackage('drupal/core'); - } - return $this->drupalCorePackage; - } - - /** - * Retrieve a package from the current composer process. - * - * @param string $name - * Name of the package to get from the current composer installation. - * - * @return \Composer\Package\PackageInterface - * The package. - */ - protected function getPackage($name) { - return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*'); - } +class Handler extends BaseHandler { /** * Configure Drupal Project for Docker. @@ -84,6 +23,10 @@ class Handler { * The event that triggered the call of this function. * @param bool $overwrite * Whether to overwrite existing config files. + * + * @throws \Twig_Error_Loader + * @throws \Twig_Error_Runtime + * @throws \Twig_Error_Syntax */ public function configureProject(Event $event, $overwrite = FALSE) { @@ -335,16 +278,6 @@ class Handler { return $env->replaceEnvironmentVariables($options); } - /** - * Wrapper for git command in the root directory. - * - * @param string $command - * Git command name, arguments and/or options. - */ - protected function git($command) { - passthru(escapeshellcmd('git -c "user.email=d8-project@lakedrops.com" ' . $command)); - } - /** * Determine local ipv4 address. * diff --git a/src/Plugin.php b/src/Plugin.php index af56d8fc9d499f7383e4e5d88964e31627724ea8..2d6363eaad59976af33c40ad9521420d74b6daf3 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -2,30 +2,20 @@ namespace LakeDrops\Docker4Drupal; -use Composer\Composer; -use Composer\EventDispatcher\EventSubscriberInterface; -use Composer\IO\IOInterface; -use Composer\Plugin\PluginInterface; use Composer\Script\Event; use Composer\Script\ScriptEvents; +use LakeDrops\Component\Composer\BasePlugin; /** * Composer plugin for handling docker4drupal setup. */ -class Plugin implements PluginInterface, EventSubscriberInterface { - - /** - * The handler object to configure the project for docker. - * - * @var \LakeDrops\Docker4Drupal\Handler - */ - protected $handler; +class Plugin extends BasePlugin { /** * {@inheritdoc} */ - public function activate(Composer $composer, IOInterface $io) { - $this->handler = new Handler($composer, $io); + public function getHandlerClass() { + return Handler::class; } /** @@ -54,6 +44,10 @@ class Plugin implements PluginInterface, EventSubscriberInterface { * * @param \Composer\Script\Event $event * The event that triggered the call of this function. + * + * @throws \Twig_Error_Loader + * @throws \Twig_Error_Runtime + * @throws \Twig_Error_Syntax */ public static function config(Event $event) { $handler = new Handler($event->getComposer(), $event->getIO());