Skip to content

Commit 702f252

Browse files
committed
[#2145] Fixed installer script requiring curl.
1 parent bc92332 commit 702f252

9 files changed

Lines changed: 1290 additions & 1148 deletions

File tree

.vortex/installer/src/Command/InstallCommand.php

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace DrevOps\VortexInstaller\Command;
66

77
use DrevOps\VortexInstaller\Downloader\Downloader;
8+
use DrevOps\VortexInstaller\Downloader\RepositoryDownloader;
89
use DrevOps\VortexInstaller\Prompts\Handlers\Starter;
910
use DrevOps\VortexInstaller\Prompts\PromptManager;
1011
use DrevOps\VortexInstaller\Runner\CommandRunnerAwareInterface;
@@ -75,9 +76,14 @@ class InstallCommand extends Command implements CommandRunnerAwareInterface, Exe
7576
protected PromptManager $promptManager;
7677

7778
/**
78-
* The downloader.
79+
* The repository downloader.
7980
*/
80-
protected ?Downloader $downloader = NULL;
81+
protected ?RepositoryDownloader $repositoryDownloader = NULL;
82+
83+
/**
84+
* The file downloader.
85+
*/
86+
protected ?Downloader $fileDownloader = NULL;
8187

8288
/**
8389
* {@inheritdoc}
@@ -147,11 +153,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
147153
Task::action(
148154
label: 'Downloading Vortex',
149155
action: function (): string {
150-
$version = $this->getDownloader()->download($this->config->get(Config::REPO), $this->config->get(Config::REF), $this->config->get(Config::TMP));
156+
$version = $this->getRepositoryDownloader()->download($this->config->get(Config::REPO), $this->config->get(Config::REF), $this->config->get(Config::TMP));
151157
$this->config->set(Config::VERSION, $version);
152158
return $version;
153159
},
154-
hint: fn(): string => sprintf('Downloading from "%s" repository at commit "%s"', ...Downloader::parseUri($this->config->get(Config::REPO))),
160+
hint: fn(): string => sprintf('Downloading from "%s" repository at commit "%s"', ...RepositoryDownloader::parseUri($this->config->get(Config::REPO))),
155161
success: fn(string $return): string => sprintf('Vortex downloaded (%s)', $return)
156162
);
157163

@@ -234,7 +240,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
234240
protected function checkRequirements(): void {
235241
$required_commands = [
236242
'git',
237-
'curl',
238243
'tar',
239244
'composer',
240245
];
@@ -296,7 +301,7 @@ protected function resolveOptions(array $arguments, array $options): void {
296301
Env::putFromDotenv($dest_env_file);
297302
}
298303

299-
[$repo, $ref] = Downloader::parseUri($options[static::OPTION_URI] ?: 'https://github.com/drevops/vortex.git@stable');
304+
[$repo, $ref] = RepositoryDownloader::parseUri($options[static::OPTION_URI] ?: 'https://github.com/drevops/vortex.git@stable');
300305
$this->config->set(Config::REPO, $repo);
301306
$this->config->set(Config::REF, $ref);
302307

@@ -425,10 +430,8 @@ protected function prepareDemo(): array|string {
425430
$messages[] = sprintf('Created data directory "%s".', $data_dir);
426431
}
427432

428-
$command = sprintf('curl -s -L "%s" -o "%s/%s"', $url, $data_dir, $db_file);
429-
if (passthru($command) === FALSE) {
430-
throw new \RuntimeException(sprintf('Unable to download demo database from %s.', $url));
431-
}
433+
$destination = $data_dir . DIRECTORY_SEPARATOR . $db_file;
434+
$this->getFileDownloader()->download($url, $destination);
432435

433436
$messages[] = sprintf('No database dump file was found in "%s" directory.', $data_dir);
434437
$messages[] = sprintf('Downloaded demo database from %s.', $url);
@@ -506,10 +509,10 @@ protected function header(): void {
506509
$content = '';
507510

508511
$ref = $this->config->get(Config::REF);
509-
if ($ref == Downloader::REF_STABLE) {
512+
if ($ref == RepositoryDownloader::REF_STABLE) {
510513
$content .= 'This tool will guide you through installing the latest ' . Tui::underscore('stable') . ' version of Vortex into your project.' . PHP_EOL;
511514
}
512-
elseif ($ref == Downloader::REF_HEAD) {
515+
elseif ($ref == RepositoryDownloader::REF_HEAD) {
513516
$content .= 'This tool will guide you through installing the latest ' . Tui::underscore('development') . ' version of Vortex into your project.' . PHP_EOL;
514517
}
515518
else {
@@ -713,26 +716,49 @@ public function cleanup(): void {
713716
}
714717

715718
/**
716-
* Get the downloader.
719+
* Get the repository downloader.
720+
*
721+
* Provides a default RepositoryDownloader instance or returns the injected
722+
* one. This allows tests to inject mocks via setRepositoryDownloader().
723+
*
724+
* @return \DrevOps\VortexInstaller\Downloader\RepositoryDownloader
725+
* The repository downloader.
726+
*/
727+
protected function getRepositoryDownloader(): RepositoryDownloader {
728+
return $this->repositoryDownloader ??= new RepositoryDownloader();
729+
}
730+
731+
/**
732+
* Set the repository downloader.
733+
*
734+
* @param \DrevOps\VortexInstaller\Downloader\RepositoryDownloader $repositoryDownloader
735+
* The repository downloader.
736+
*/
737+
public function setRepositoryDownloader(RepositoryDownloader $repositoryDownloader): void {
738+
$this->repositoryDownloader = $repositoryDownloader;
739+
}
740+
741+
/**
742+
* Get the file downloader.
717743
*
718744
* Provides a default Downloader instance or returns the injected one.
719-
* This allows tests to inject mocks via setDownloader().
745+
* This allows tests to inject mocks via setFileDownloader().
720746
*
721747
* @return \DrevOps\VortexInstaller\Downloader\Downloader
722-
* The downloader.
748+
* The file downloader.
723749
*/
724-
protected function getDownloader(): Downloader {
725-
return $this->downloader ??= new Downloader();
750+
protected function getFileDownloader(): Downloader {
751+
return $this->fileDownloader ??= new Downloader();
726752
}
727753

728754
/**
729-
* Set the downloader.
755+
* Set the file downloader.
730756
*
731-
* @param \DrevOps\VortexInstaller\Downloader\Downloader $downloader
732-
* The downloader.
757+
* @param \DrevOps\VortexInstaller\Downloader\Downloader $fileDownloader
758+
* The file downloader.
733759
*/
734-
public function setDownloader(Downloader $downloader): void {
735-
$this->downloader = $downloader;
760+
public function setFileDownloader(Downloader $fileDownloader): void {
761+
$this->fileDownloader = $fileDownloader;
736762
}
737763

738764
}

0 commit comments

Comments
 (0)