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

Build interface for BaseHandler

Add method to determine if process runs in a CI/CD context
parent 2bf8c7ae
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ use Composer\IO\IOInterface;
*
* @package LakeDrops\Component\Composer
*/
abstract class BaseHandler {
abstract class BaseHandler implements BaseHandlerInterface {
/**
* The composer object of this session.
......@@ -47,12 +47,9 @@ abstract class BaseHandler {
}
/**
* Look up the Drupal core package object.
*
* @return \Composer\Package\PackageInterface
* The Drupal core package.
* {@inheritdoc}
*/
protected function getDrupalCorePackage() {
public function getDrupalCorePackage() {
if (!isset($this->drupalCorePackage)) {
$this->drupalCorePackage = $this->getPackage('drupal/core');
}
......@@ -60,25 +57,24 @@ abstract class BaseHandler {
}
/**
* 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.
* {@inheritdoc}
*/
protected function getPackage($name) {
public 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.
* {@inheritdoc}
*/
public function isCiContext() {
$ci_project_dir = getenv('CI_PROJECT_DIR');
return !empty($ci_project_dir );
}
/**
* {@inheritdoc}
*/
protected function git($command) {
public function git($command) {
passthru(escapeshellcmd('git -c "user.email=composer@lakedrops.com" ' . $command));
}
......
......@@ -9,4 +9,38 @@ namespace LakeDrops\Component\Composer;
*/
interface BaseHandlerInterface {
/**
* Look up the Drupal core package object.
*
* @return \Composer\Package\PackageInterface
* The Drupal core package.
*/
public function getDrupalCorePackage();
/**
* 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.
*/
public function getPackage($name);
/**
* Determine if the current process runs in a CI/CD context.
*
* @return bool
*/
public function isCiContext();
/**
* Wrapper for git command in the root directory.
*
* @param string $command
* Git command name, arguments and/or options.
*/
public function git($command);
}
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