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

Provide abstract classes and interfaces for LakeDrops plugins

parent 2a899647
No related branches found
No related tags found
No related merge requests found
<?php
namespace LakeDrops\Component\Composer;
use Composer\Composer;
use Composer\IO\IOInterface;
/**
* Class BaseHandler.
*
* @package LakeDrops\Component\Composer
*/
abstract class BaseHandler {
/**
* 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, '*');
}
/**
* 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=composer@lakedrops.com" ' . $command));
}
}
<?php
namespace LakeDrops\Component\Composer;
/**
* Interface for BaseHandler.
*
* @package LakeDrops\Component\Composer
*/
interface BaseHandlerInterface {
}
<?php
namespace LakeDrops\Component\Composer;
use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
/**
* Composer plugin for handling docker4drupal setup.
*/
abstract class BasePlugin implements BasePluginInterface, PluginInterface, EventSubscriberInterface {
/**
* The handler object to do the real work then.
*
* @var \LakeDrops\Component\Composer\BaseHandlerInterface
*/
protected $handler;
/**
* {@inheritdoc}
*/
public function activate(Composer $composer, IOInterface $io) {
$class = $this->getHandlerClass();
$this->handler = new $class($composer, $io);
}
}
<?php
namespace LakeDrops\Component\Composer;
/**
* Interface for BasePlugin.
*
* @package LakeDrops\Component\Composer
*/
interface BasePluginInterface {
/**
* @return \LakeDrops\Component\Composer\BaseHandlerInterface
*/
public function getHandlerClass();
}
......@@ -78,12 +78,17 @@ final class Utils {
$jsonFile = new JsonFile($this->composerJsonPath);
if (file_exists($this->composerJsonPath)) {
$content = $jsonFile->read();
if (md5(json_encode($content)) == md5(json_encode($this->content))) {
if (md5(json_encode($content)) === md5(json_encode($this->content))) {
// Nothing has changed.
return $this;
}
}
$jsonFile->write($this->content);
try {
$jsonFile->write($this->content);
}
catch (\Exception $ex) {
// Let's ignore this, if composer.json is read-only there is a general problem.
}
return $this;
}
......
......@@ -24,7 +24,8 @@
"source": "https://gitlab.lakedrops.com/composer/library/composer-json-utils/tree/master"
},
"require": {
"php": ">=5.6"
"php": ">=5.6",
"ext-json": "*"
},
"require-dev": {
"composer/composer": "^1.5.0",
......
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