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

Refactor namespace to extend LakeDrops Composer Components

parent ca0ddfa3
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,8 @@
namespace LakeDrops\Behat4Drupal;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Script\Event;
use LakeDrops\Component\Composer\BaseHandler;
use LakeDrops\Component\Dotenv\Dotenv;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;
......@@ -14,47 +13,7 @@ use Symfony\Component\Yaml\Yaml;
*
* @package LakeDrops\Behat4Drupal
*/
class Handler {
/**
* 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;
/**
* 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;
}
/**
* 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 {
/**
* Post project create event to execute the scaffolding.
......@@ -63,6 +22,10 @@ class Handler {
* The event that triggered the plugin.
* @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) {
......@@ -95,6 +58,7 @@ class Handler {
$rendered = $twig->render($filename, $options);
if (!empty($def['add2yaml']) && isset($options[$filename])) {
$yaml = Yaml::parse($rendered);
/** @noinspection SlowArrayOperationsInLoopInspection */
$yaml = array_merge_recursive($yaml, $options[$filename]);
$rendered = Yaml::dump($yaml, 9, 2);
}
......@@ -150,9 +114,10 @@ class Handler {
$env = new Dotenv('behat4drupal', $this->io);
$env->put('COMPOSE_PROJECT_NAME', $projectname);
$extra = $this->composer->getPackage()->getExtra() + ['behat4drupal' => []];
return $extra['behat4drupal'] + [
$options = $extra['behat4drupal'] + [
'projectname' => $projectname,
];
return $env->replaceEnvironmentVariables($options);
}
}
......@@ -2,30 +2,20 @@
namespace LakeDrops\Behat4Drupal;
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 drupal scaffold.
*/
class Plugin implements PluginInterface, EventSubscriberInterface {
/**
* The handler object for events.
*
* @var \LakeDrops\Behat4Drupal\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;
}
/**
......@@ -52,6 +42,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());
......
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