Skip to content
Snippets Groups Projects
Commit 596dff2a authored by jurgenhaas's avatar jurgenhaas
Browse files

Refactor namespace to extend LakeDrops Composer Components

parent 08709055
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,8 @@ namespace LakeDrops\Drupal8ScaffoldDeveloper; ...@@ -5,6 +5,8 @@ namespace LakeDrops\Drupal8ScaffoldDeveloper;
use Composer\Composer; use Composer\Composer;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Script\Event; use Composer\Script\Event;
use LakeDrops\Component\Composer\BaseHandler;
use LakeDrops\Component\Dotenv\Dotenv;
use LakeDrops\Docker4Drupal\Handler as D4D; use LakeDrops\Docker4Drupal\Handler as D4D;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
...@@ -13,76 +15,17 @@ use Symfony\Component\Filesystem\Filesystem; ...@@ -13,76 +15,17 @@ use Symfony\Component\Filesystem\Filesystem;
* *
* @package LakeDrops\Drupal8ScaffoldDeveloper * @package LakeDrops\Drupal8ScaffoldDeveloper
*/ */
class Handler { class Handler extends BaseHandler {
/**
* The composer object running this session.
*
* @var \Composer\Composer
*/
protected $composer;
/**
* The input-output object for 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.
* @param \Composer\IO\IOInterface $io
* The input-output object.
*/
public function __construct(Composer $composer, IOInterface $io) {
$this->composer = $composer;
$this->io = $io;
}
/**
* Get the Drupal Core package.
*
* Look up the Drupal core package object, or return it from where we cached
* it in the $drupalCorePackage field.
*
* @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, '*');
}
/** /**
* Post project create event to execute the scaffolding. * Post project create event to execute the scaffolding.
* *
* @param \Composer\Script\Event $event * @param \Composer\Script\Event $event
* The event that triggered the plugin. * The event that triggered the plugin.
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/ */
public function setupLakeDropsProject(Event $event) { public function setupLakeDropsProject(Event $event) {
...@@ -251,22 +194,8 @@ class Handler { ...@@ -251,22 +194,8 @@ class Handler {
'allowedOrigins' => '*', 'allowedOrigins' => '*',
], ],
]; ];
return $options; $env = new Dotenv('lakedrops', $this->io);
} return $env->replaceEnvironmentVariables($options);
/**
* Wrapper for git command in the root directory.
*
* @param string $command
* Git command name, arguments and/or options.
*
* @throws \Exception
*/
protected function git($command) {
passthru(escapeshellcmd('git -c "user.email=d8-project@lakedrops.com" ' . $command), $exit_code);
if ($exit_code !== 0) {
throw new \Exception('Git returned a non-zero exit code');
}
} }
} }
...@@ -3,24 +3,16 @@ ...@@ -3,24 +3,16 @@
namespace LakeDrops\Drupal8ScaffoldDeveloper; namespace LakeDrops\Drupal8ScaffoldDeveloper;
use Composer\Composer; use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\Event; use Composer\Script\Event;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use DrupalComposer\DrupalScaffold\Handler as DrupalScaffoldHandler; use DrupalComposer\DrupalScaffold\Handler as DrupalScaffoldHandler;
use LakeDrops\Component\Composer\BasePlugin;
/** /**
* Composer plugin for handling drupal scaffold. * Composer plugin for handling drupal scaffold.
*/ */
class Plugin implements PluginInterface, EventSubscriberInterface { class Plugin extends BasePlugin {
/**
* The handler object for events.
*
* @var \LakeDrops\Drupal8ScaffoldDeveloper\Handler
*/
protected $handler;
/** /**
* The scaffold handler object for events. * The scaffold handler object for events.
...@@ -33,18 +25,25 @@ class Plugin implements PluginInterface, EventSubscriberInterface { ...@@ -33,18 +25,25 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function activate(Composer $composer, IOInterface $io) { public function activate(Composer $composer, IOInterface $io) {
$this->handler = new Handler($composer, $io); parent::activate($composer, $io);
$this->scaffoldHandler = new DrupalScaffoldHandler($composer, $io); $this->scaffoldHandler = new DrupalScaffoldHandler($composer, $io);
} }
/**
* {@inheritdoc}
*/
public function getHandlerClass() {
return Handler::class;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function getSubscribedEvents() { public static function getSubscribedEvents() {
return array( return [
ScriptEvents::POST_CREATE_PROJECT_CMD => 'postCreateProject', ScriptEvents::POST_CREATE_PROJECT_CMD => 'postCreateProject',
ScriptEvents::POST_UPDATE_CMD => 'postUpdate', ScriptEvents::POST_UPDATE_CMD => 'postUpdate',
); ];
} }
/** /**
...@@ -73,6 +72,10 @@ class Plugin implements PluginInterface, EventSubscriberInterface { ...@@ -73,6 +72,10 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
* *
* @param \Composer\Script\Event $event * @param \Composer\Script\Event $event
* The event that triggered the plugin. * The event that triggered the plugin.
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/ */
public static function scaffold(Event $event) { public static function scaffold(Event $event) {
$handler = new Handler($event->getComposer(), $event->getIO()); $handler = new Handler($event->getComposer(), $event->getIO());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment