diff --git a/composer.json b/composer.json index d922c63dd4519784260d81fa9e66941185fa7e5e..78e3ddb737c53b9fb4f60337bfb6da7c74c8e08c 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "drush-ops/behat-drush-endpoint": "^9.2", "jcalderonzumba/gastonjs": "^1.2", "jcalderonzumba/mink-phantomjs-driver": "^0.3", - "lakedrops/composer-scripts": "^1.0.0", + "lakedrops/composer-scripts": "^1.1.0", "lakedrops/docker4drupal": "^1.0.0", "lakedrops/dotenv": "^1.0.0", "php": ">=5.6", diff --git a/src/Handler.php b/src/Handler.php index 56da1fbfecb6ce347cf4ac2204ff1acbbacec8e2..4dfc0f514ff919b7ccdf0b275a44d9833f32a2e8 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -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); } } diff --git a/src/Plugin.php b/src/Plugin.php index d6305600de8061a4314b3efc8e0aab50fe078906..0e6d9f724c72f8d3feb6e2738cb3d3ade7322263 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -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());