Skip to content

Commit

Permalink
Added comments to installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Feb 3, 2024
1 parent 5b14ffd commit 640bf7b
Show file tree
Hide file tree
Showing 72 changed files with 969 additions and 216 deletions.
2 changes: 2 additions & 0 deletions .drevops/installer/src/Bag/AbstractBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace DrevOps\Installer\Bag;

/**
* Class AbstractBag.
*
* Bag to store and manipulate items.
*/
abstract class AbstractBag {

Expand Down
2 changes: 2 additions & 0 deletions .drevops/installer/src/Bag/Answers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use DrevOps\Installer\Trait\SingletonTrait;

/**
* Class Answers.
*
* Bag to store answers.
*/
class Answers extends AbstractBag {

Expand Down
31 changes: 16 additions & 15 deletions .drevops/installer/src/Bag/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use DrevOps\Installer\Utils\Files;

/**
* Class Config.
*
* Bag to store configuration.
*/
class Config extends AbstractBag {

Expand Down Expand Up @@ -49,16 +51,7 @@ public function __construct() {
}

/**
* Set installer configuration.
*
* Installer config is a config of this installer script. For configs of the
* project being installed, @param $name.
*
* @param $value
*
* @see set_answer()
*
* @see init_config()
* {@inheritdoc}
*/
public function set(string $name, mixed $value): void {
if ($this->isReadOnly()) {
Expand Down Expand Up @@ -89,19 +82,21 @@ public function fromValues($values = []): AbstractBag {
/**
* Shorthand to get the value of whether install should be quiet.
*
* @return mixed|null
* @return bool
* Whether install should be quiet.
*/
public function isQuiet() {
return $this->get('quiet', FALSE);
public function isQuiet(): bool {
return (bool) $this->get('quiet', FALSE);
}

/**
* Shorthand to get the value the destination directory.
*
* @return mixed|null
* @return string
* The destination directory.
*/
public function getDstDir(): string {
return $this->get(Env::INSTALLER_DST_DIR, getcwd());
return (string) $this->get(Env::INSTALLER_DST_DIR, getcwd());
}

/**
Expand All @@ -111,6 +106,12 @@ public function getWebroot(): string {
return $this->get(Env::WEBROOT, 'web');
}

/**
* Collect values from environment.
*
* @param array $defaults
* Default values.
*/
protected function collectFromEnv(array $defaults = []): void {
$constants = Env::getConstants();

Expand Down
33 changes: 25 additions & 8 deletions .drevops/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,29 @@ class InstallCommand extends Command {
protected static $defaultName = 'install';

/**
* Config.
*
* @var \DrevOps\Installer\Bag\Config
*/
protected $config;

/**
* Prompt manager.
*
* @var \DrevOps\Installer\Prompt\PromptManager
*/
protected $questionManager;
protected $promptManager;

/**
* Install manager.
*
* @var \DrevOps\Installer\InstallManager
*/
protected $installManager;

/**
* Print manager.
*
* @var \DrevOps\Installer\PrintManager
*/
protected $printManager;
Expand All @@ -86,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->config = Config::getInstance()->fromValues(['cwd' => getcwd()] + $input->getArguments() + $input->getOptions());

$io = $this->initIo($input, $output);
$this->questionManager = new PromptManager($io, $this->config);
$this->promptManager = new PromptManager($io, $this->config);
$this->printManager = new PrintManager($io, $this->config);

return $this->doExecute();
Expand Down Expand Up @@ -117,8 +125,11 @@ protected function doExecute(): int {
return self::SUCCESS;
}

/**
* Ask questions and return a bag of answers.
*/
protected function askQuestions(): AbstractBag {
$this->questionManager->askQuestions(function (PromptManager $qm): void {
$this->promptManager->askQuestions(function (PromptManager $qm): void {
$is_installed = InstallManager::isInstalled($this->config->getDstDir());

// // @todo remove this.
Expand Down Expand Up @@ -197,18 +208,24 @@ protected function askQuestions(): AbstractBag {
});

if (!$this->config->isQuiet()) {
$summary = $this->questionManager->getAnswersSummary();
$summary = $this->promptManager->getAnswersSummary();
$this->printManager->printSummary($summary, 'INSTALLATION SUMMARY');
}

return $this->questionManager->getAnswers();
return $this->promptManager->getAnswers();
}

protected function askShouldProceed() {
/**
* Ask whether to proceed with the installation.
*
* @return bool
* Whether to proceed with the installation.
*/
protected function askShouldProceed(): bool {
$proceed = TRUE;

if (!$this->config->isQuiet()) {
$proceed = $this->questionManager->ask(ProceedDrevopsInstallPrompt::ID);
$proceed = $this->promptManager->ask(ProceedDrevopsInstallPrompt::ID);
}

// Kill-switch to not proceed with install. If false, the installation will
Expand All @@ -221,7 +238,7 @@ protected function askShouldProceed() {
}

/**
* Initialise output.
* Initialise the input/output.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* Output.
Expand Down
45 changes: 39 additions & 6 deletions .drevops/installer/src/InstallManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
use DrevOps\Installer\Utils\Executor;
use DrevOps\Installer\Utils\Files;
use DrevOps\Installer\Utils\Output;
use DrevOps\Installer\Utils\Tokenizer;

/**
*
* Install manager.
*/
class InstallManager {

Expand All @@ -18,8 +19,18 @@ class InstallManager {
*/
final public const INSTALLER_DRUPAL_VERSION = 9;

/**
* Download manager.
*
* @var \DrevOps\Installer\Utils\Downloader
*/
protected $downloadManager;

/**
* Config.
*
* @var \DrevOps\Installer\Bag\Config
*/
protected $config;

/**
Expand All @@ -34,16 +45,35 @@ public static function isInstalled(string $dst_dir): bool {
}

public function install($config): void {
$this->config = $config;

$this->checkRequirements();

$this->downloadManager->download();

$this->prepareDestination();

Tokenizer::replaceTokens();

$this->copyFiles();

ProcessorManager::processDemo();
}

/**
* Check requirements.
*/
public function checkRequirements(): void {
Executor::commandExists('git');
Executor::commandExists('tar');
Executor::commandExists('composer');
Executor::validateCommandExists('git');
Executor::validateCommandExists('tar');
Executor::validateCommandExists('composer');
}

/**
* Prepare destination directory.
*/
public function prepareDestination(): void {
$dst = Config::getDstDir();
$dst = Config::getInstance()->getDstDir();

if (!is_dir($dst)) {
Output::status(sprintf('Creating destination directory "%s".', $dst), Output::INSTALLER_STATUS_MESSAGE, FALSE);
Expand All @@ -69,8 +99,11 @@ public function prepareDestination(): void {
Output::status('Done', Output::INSTALLER_STATUS_SUCCESS);
}

/**
* Copy files.
*/
public function copyFiles(): void {
$src = Config::get(Env::INSTALLER_TMP_DIR);
$src = Config::getInstance()->get(Env::INSTALLER_TMP_DIR);
$dst = Config::getDstDir();

// Due to the way symlinks can be ordered, we cannot copy files one-by-one
Expand Down
5 changes: 4 additions & 1 deletion .drevops/installer/src/InstallerApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
use Symfony\Component\Console\Application;

/**
*
* Installer application.
*/
class InstallerApp extends Application {

/**
* {@inheritdoc}
*/
public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN') {
parent::__construct($name, $version);

Expand Down
26 changes: 23 additions & 3 deletions .drevops/installer/src/PrintManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;

/**
*
* Print manager.
*/
class PrintManager {

Expand All @@ -25,6 +25,9 @@ public function printHeader(): void {
}
}

/**
* Print header for interactive mode.
*/
public function printHeaderInteractive(): void {
$commit = $this->config->get(Env::INSTALLER_COMMIT);

Expand Down Expand Up @@ -53,6 +56,9 @@ public function printHeaderInteractive(): void {
Formatter::printBox($this->io, $content, 'WELCOME TO DREVOPS INTERACTIVE INSTALLER');
}

/**
* Print header for quiet mode.
*/
public function printHeaderQuiet(): void {
$commit = $this->config->get(Env::INSTALLER_COMMIT);

Expand All @@ -78,19 +84,33 @@ public function printHeaderQuiet(): void {
$this->io->setVerbosity($verbosity_level);
}

/**
* Print summary.
*
* @param array $values
* The values to print.
* @param string $title
* The title.
*/
public function printSummary($values, $title): void {
$values = array_map(static function ($key, $value) : array {
return [$key => $value];
$values = array_map(static function ($key, $value): array {
return [$key => $value];
}, array_keys($values), $values);

$this->io->writeln(sprintf(' <options=bold>%s</>', $title));
$this->io->definitionList(...$values);
}

/**
* Print abort message.
*/
public function printAbort(): void {
Formatter::printBox($this->io, 'Aborting DrevOps installation. No files were changed.', 'INSTALLATION ABORTED');
}

/**
* Print footer.
*/
public function printFooter(): void {
$output = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
*
* Database download source processor.
*/
class DatabaseDownloadSourceProcessor extends AbstractProcessor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
*
* Database download source processor.
*/
class DatabaseImageProcessor extends AbstractProcessor {

Expand Down
2 changes: 1 addition & 1 deletion .drevops/installer/src/Processor/DemoModeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
*
* Demo mode processor.
*/
class DemoModeProcessor extends AbstractProcessor {

Expand Down
2 changes: 1 addition & 1 deletion .drevops/installer/src/Processor/DemoProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
*
* Demo processor.
*/
class DemoProcessor extends AbstractProcessor {

Expand Down
2 changes: 1 addition & 1 deletion .drevops/installer/src/Processor/DeployTypeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
*
* Deploy type processor.
*/
class DeployTypeProcessor extends AbstractProcessor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
*
* DrevOps internal processor.
*/
class DrevopsInternalProcess extends AbstractProcessor {

Expand Down
Loading

0 comments on commit 640bf7b

Please sign in to comment.