diff --git a/BaseHandler.php b/BaseHandler.php index 2ade1b5d3c16657485f5718cba945bb723d1e1e1..3cd0de21e34ec8dbc52d0f377a187f4f09c37a27 100644 --- a/BaseHandler.php +++ b/BaseHandler.php @@ -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)); } diff --git a/BaseHandlerInterface.php b/BaseHandlerInterface.php index 135a49926a002a336f70079480d87562a5b8fd85..8ea968aeabaaa928dc59a46919a94fd02aa7cb33 100644 --- a/BaseHandlerInterface.php +++ b/BaseHandlerInterface.php @@ -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); + }