2025-04-08 23:00:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Loom\Spinner\Command;
|
|
|
|
|
2025-04-12 15:14:28 +01:00
|
|
|
use Loom\Spinner\Classes\Collection\FilePathCollection;
|
|
|
|
use Loom\Spinner\Classes\File\SpinnerFilePath;
|
|
|
|
use Loom\Spinner\Classes\OS\System;
|
|
|
|
use Loom\Spinner\Command\Interface\ConsoleCommandInterface;
|
|
|
|
use Loom\Utility\FilePath\FilePath;
|
2025-04-08 23:00:21 +01:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
|
2025-04-12 15:14:28 +01:00
|
|
|
class AbstractSpinnerCommand extends Command implements ConsoleCommandInterface
|
2025-04-08 23:00:21 +01:00
|
|
|
{
|
|
|
|
protected SymfonyStyle $style;
|
2025-04-12 10:47:55 +01:00
|
|
|
protected System $system;
|
2025-04-12 15:14:28 +01:00
|
|
|
protected FilePathCollection $filePaths;
|
|
|
|
protected string $rootDirectory;
|
2025-04-12 10:47:55 +01:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
2025-04-12 15:14:28 +01:00
|
|
|
$this->rootDirectory = dirname(__DIR__, 2);
|
2025-04-12 10:47:55 +01:00
|
|
|
$this->system = new System();
|
2025-04-12 15:14:28 +01:00
|
|
|
$this->setFilePaths();
|
2025-04-12 10:47:55 +01:00
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
2025-04-08 23:00:21 +01:00
|
|
|
|
2025-04-12 15:14:28 +01:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
|
|
|
$this->setStyle($input, $output);
|
|
|
|
|
|
|
|
if (!$this->system->isDockerEngineRunning()) {
|
|
|
|
$this->style->error('It looks like the Docker Engine is not running. Please start it and try again.');
|
|
|
|
|
|
|
|
return Command::FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($input->hasArgument('path')) {
|
|
|
|
$projectDirectory = new FilePath($input->getArgument('path'));
|
|
|
|
|
|
|
|
if (!$projectDirectory->exists() || !$projectDirectory->isDirectory()) {
|
|
|
|
$this->style->error('The provided path is not a valid directory.');
|
|
|
|
|
|
|
|
return Command::FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->filePaths->add($projectDirectory, 'project');
|
|
|
|
}
|
|
|
|
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function setStyle(InputInterface $input, OutputInterface $output): void
|
2025-04-08 23:00:21 +01:00
|
|
|
{
|
|
|
|
$this->style = new SymfonyStyle($input, $output);
|
|
|
|
}
|
2025-04-12 15:14:28 +01:00
|
|
|
|
|
|
|
private function setFilePaths(): void
|
|
|
|
{
|
|
|
|
$this->filePaths = new FilePathCollection([
|
|
|
|
'config' => new SpinnerFilePath('config'),
|
|
|
|
]);
|
|
|
|
}
|
2025-04-08 23:00:21 +01:00
|
|
|
}
|