|
5 | 5 | namespace DrevOps\VortexInstaller\Command; |
6 | 6 |
|
7 | 7 | use DrevOps\VortexInstaller\Downloader\Downloader; |
| 8 | +use DrevOps\VortexInstaller\Downloader\RepositoryDownloader; |
8 | 9 | use DrevOps\VortexInstaller\Prompts\Handlers\Starter; |
9 | 10 | use DrevOps\VortexInstaller\Prompts\PromptManager; |
10 | 11 | use DrevOps\VortexInstaller\Runner\CommandRunnerAwareInterface; |
@@ -75,9 +76,14 @@ class InstallCommand extends Command implements CommandRunnerAwareInterface, Exe |
75 | 76 | protected PromptManager $promptManager; |
76 | 77 |
|
77 | 78 | /** |
78 | | - * The downloader. |
| 79 | + * The repository downloader. |
79 | 80 | */ |
80 | | - protected ?Downloader $downloader = NULL; |
| 81 | + protected ?RepositoryDownloader $repositoryDownloader = NULL; |
| 82 | + |
| 83 | + /** |
| 84 | + * The file downloader. |
| 85 | + */ |
| 86 | + protected ?Downloader $fileDownloader = NULL; |
81 | 87 |
|
82 | 88 | /** |
83 | 89 | * {@inheritdoc} |
@@ -147,11 +153,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
147 | 153 | Task::action( |
148 | 154 | label: 'Downloading Vortex', |
149 | 155 | 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)); |
151 | 157 | $this->config->set(Config::VERSION, $version); |
152 | 158 | return $version; |
153 | 159 | }, |
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))), |
155 | 161 | success: fn(string $return): string => sprintf('Vortex downloaded (%s)', $return) |
156 | 162 | ); |
157 | 163 |
|
@@ -234,7 +240,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
234 | 240 | protected function checkRequirements(): void { |
235 | 241 | $required_commands = [ |
236 | 242 | 'git', |
237 | | - 'curl', |
238 | 243 | 'tar', |
239 | 244 | 'composer', |
240 | 245 | ]; |
@@ -296,7 +301,7 @@ protected function resolveOptions(array $arguments, array $options): void { |
296 | 301 | Env::putFromDotenv($dest_env_file); |
297 | 302 | } |
298 | 303 |
|
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'); |
300 | 305 | $this->config->set(Config::REPO, $repo); |
301 | 306 | $this->config->set(Config::REF, $ref); |
302 | 307 |
|
@@ -425,10 +430,8 @@ protected function prepareDemo(): array|string { |
425 | 430 | $messages[] = sprintf('Created data directory "%s".', $data_dir); |
426 | 431 | } |
427 | 432 |
|
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); |
432 | 435 |
|
433 | 436 | $messages[] = sprintf('No database dump file was found in "%s" directory.', $data_dir); |
434 | 437 | $messages[] = sprintf('Downloaded demo database from %s.', $url); |
@@ -506,10 +509,10 @@ protected function header(): void { |
506 | 509 | $content = ''; |
507 | 510 |
|
508 | 511 | $ref = $this->config->get(Config::REF); |
509 | | - if ($ref == Downloader::REF_STABLE) { |
| 512 | + if ($ref == RepositoryDownloader::REF_STABLE) { |
510 | 513 | $content .= 'This tool will guide you through installing the latest ' . Tui::underscore('stable') . ' version of Vortex into your project.' . PHP_EOL; |
511 | 514 | } |
512 | | - elseif ($ref == Downloader::REF_HEAD) { |
| 515 | + elseif ($ref == RepositoryDownloader::REF_HEAD) { |
513 | 516 | $content .= 'This tool will guide you through installing the latest ' . Tui::underscore('development') . ' version of Vortex into your project.' . PHP_EOL; |
514 | 517 | } |
515 | 518 | else { |
@@ -713,26 +716,49 @@ public function cleanup(): void { |
713 | 716 | } |
714 | 717 |
|
715 | 718 | /** |
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. |
717 | 743 | * |
718 | 744 | * 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(). |
720 | 746 | * |
721 | 747 | * @return \DrevOps\VortexInstaller\Downloader\Downloader |
722 | | - * The downloader. |
| 748 | + * The file downloader. |
723 | 749 | */ |
724 | | - protected function getDownloader(): Downloader { |
725 | | - return $this->downloader ??= new Downloader(); |
| 750 | + protected function getFileDownloader(): Downloader { |
| 751 | + return $this->fileDownloader ??= new Downloader(); |
726 | 752 | } |
727 | 753 |
|
728 | 754 | /** |
729 | | - * Set the downloader. |
| 755 | + * Set the file downloader. |
730 | 756 | * |
731 | | - * @param \DrevOps\VortexInstaller\Downloader\Downloader $downloader |
732 | | - * The downloader. |
| 757 | + * @param \DrevOps\VortexInstaller\Downloader\Downloader $fileDownloader |
| 758 | + * The file downloader. |
733 | 759 | */ |
734 | | - public function setDownloader(Downloader $downloader): void { |
735 | | - $this->downloader = $downloader; |
| 760 | + public function setFileDownloader(Downloader $fileDownloader): void { |
| 761 | + $this->fileDownloader = $fileDownloader; |
736 | 762 | } |
737 | 763 |
|
738 | 764 | } |
0 commit comments