From 3fe612cb3638274a6e113c980ace7ab4178b1bb0 Mon Sep 17 00:00:00 2001 From: Danny Date: Wed, 23 Apr 2025 18:07:35 +0100 Subject: [PATCH] Remove SpinnerFilePath to fix for Unix (Windows will need work) --- bin/spinner | 0 src/Classes/Config/Config.php | 27 +++++++++---------- src/Classes/File/AbstractFileBuilder.php | 3 ++- src/Classes/File/DockerComposeFileBuilder.php | 7 ++--- src/Classes/File/NginxDockerFileBuilder.php | 3 ++- src/Classes/File/PHPDockerFileBuilder.php | 9 ++++--- src/Classes/File/SpinnerFilePath.php | 20 -------------- src/Command/AbstractSpinnerCommand.php | 14 +++++----- src/Command/SpinCommand.php | 10 +++---- 9 files changed, 38 insertions(+), 55 deletions(-) mode change 100644 => 100755 bin/spinner delete mode 100644 src/Classes/File/SpinnerFilePath.php diff --git a/bin/spinner b/bin/spinner old mode 100644 new mode 100755 diff --git a/src/Classes/Config/Config.php b/src/Classes/Config/Config.php index 81736a1..b992ecf 100644 --- a/src/Classes/Config/Config.php +++ b/src/Classes/Config/Config.php @@ -6,7 +6,6 @@ namespace Loom\Spinner\Classes\Config; use Loom\Spinner\Classes\Collection\FilePathCollection; use Loom\Spinner\Classes\File\Interface\DataPathInterface; -use Loom\Spinner\Classes\File\SpinnerFilePath; use Loom\Utility\FilePath\FilePath; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Yaml\Yaml; @@ -152,19 +151,19 @@ class Config private function setFilePaths(): void { $this->filePaths = new FilePathCollection([ - 'config' => new SpinnerFilePath('config'), - 'defaultSpinnerConfig' => new SpinnerFilePath('config/spinner.yaml'), - 'envTemplate' => new SpinnerFilePath('config/.template.env'), - 'data' => new SpinnerFilePath('data'), - 'phpYamlTemplate' => new SpinnerFilePath('config/php.yaml'), - 'nginxYamlTemplate' => new SpinnerFilePath('config/nginx.yaml'), - 'phpFpmDataDirectory' => new SpinnerFilePath('config/php-fpm'), - DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE), - DataPathInterface::CONFIG_NGINX_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_NGINX_DOCKERFILE), - 'nodeDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/Node.Dockerfile'), - 'xdebugIniTemplate' => new SpinnerFilePath('config/php-fpm/xdebug.ini'), - 'opcacheIniTemplate' => new SpinnerFilePath('config/php-fpm/opcache.ini'), - 'xdebugDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/XDebug.Dockerfile'), + 'config' => new FilePath('config'), + 'defaultSpinnerConfig' => new FilePath('config/spinner.yaml'), + 'envTemplate' => new FilePath('config/.template.env'), + 'data' => new FilePath('data'), + 'phpYamlTemplate' => new FilePath('config/php.yaml'), + 'nginxYamlTemplate' => new FilePath('config/nginx.yaml'), + 'phpFpmDataDirectory' => new FilePath('config/php-fpm'), + DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE => new FilePath(DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE), + DataPathInterface::CONFIG_NGINX_DOCKERFILE => new FilePath(DataPathInterface::CONFIG_NGINX_DOCKERFILE), + 'nodeDockerfileTemplate' => new FilePath('config/php-fpm/Node.Dockerfile'), + 'xdebugIniTemplate' => new FilePath('config/php-fpm/xdebug.ini'), + 'opcacheIniTemplate' => new FilePath('config/php-fpm/opcache.ini'), + 'xdebugDockerfileTemplate' => new FilePath('config/php-fpm/XDebug.Dockerfile'), ]); } } \ No newline at end of file diff --git a/src/Classes/File/AbstractFileBuilder.php b/src/Classes/File/AbstractFileBuilder.php index 26deb87..5ec53c5 100644 --- a/src/Classes/File/AbstractFileBuilder.php +++ b/src/Classes/File/AbstractFileBuilder.php @@ -6,13 +6,14 @@ namespace Loom\Spinner\Classes\File; use Loom\Spinner\Classes\Config\Config; use Loom\Spinner\Classes\File\Interface\FileBuilderInterface; +use Loom\Utility\FilePath\FilePath; use Symfony\Component\Console\Input\InputInterface; abstract class AbstractFileBuilder implements FileBuilderInterface { protected string $content; - public function __construct(protected SpinnerFilePath $path, protected Config $config) + public function __construct(protected FilePath $path, protected Config $config) { return $this; } diff --git a/src/Classes/File/DockerComposeFileBuilder.php b/src/Classes/File/DockerComposeFileBuilder.php index 2bb84d0..96d785a 100644 --- a/src/Classes/File/DockerComposeFileBuilder.php +++ b/src/Classes/File/DockerComposeFileBuilder.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Loom\Spinner\Classes\File; use Loom\Spinner\Classes\Config\Config; +use Loom\Utility\FilePath\FilePath; use Symfony\Component\Console\Input\InputInterface; class DockerComposeFileBuilder extends AbstractFileBuilder @@ -16,7 +17,7 @@ class DockerComposeFileBuilder extends AbstractFileBuilder { $projectDockerCompose = $config->getFilePaths()->get('projectDockerCompose'); - if (!$projectDockerCompose instanceof SpinnerFilePath) { + if (!$projectDockerCompose instanceof FilePath) { throw new \Exception('Project Docker Compose file path not found.'); } @@ -54,14 +55,14 @@ class DockerComposeFileBuilder extends AbstractFileBuilder ); $this->content = str_replace( './nginx/conf.d', - (new SpinnerFilePath('config/nginx/conf.d'))->getAbsolutePath(), + (new FilePath('config/nginx/conf.d'))->getAbsolutePath(), $this->content ); } private function addSqliteDatabaseConfig(): void { - $sqlLiteConfig = file_get_contents((new SpinnerFilePath('config/sqlite.yaml'))->getAbsolutePath()); + $sqlLiteConfig = file_get_contents((new FilePath('config/sqlite.yaml'))->getAbsolutePath()); $sqlLiteConfig = str_replace('volumes:', '', $sqlLiteConfig); $this->content .= $sqlLiteConfig; } diff --git a/src/Classes/File/NginxDockerFileBuilder.php b/src/Classes/File/NginxDockerFileBuilder.php index acbf58c..aecba87 100644 --- a/src/Classes/File/NginxDockerFileBuilder.php +++ b/src/Classes/File/NginxDockerFileBuilder.php @@ -6,6 +6,7 @@ namespace Loom\Spinner\Classes\File; use Loom\Spinner\Classes\Config\Config; use Loom\Spinner\Classes\File\Interface\DataPathInterface; +use Loom\Utility\FilePath\FilePath; use Symfony\Component\Console\Input\InputInterface; class NginxDockerFileBuilder extends AbstractFileBuilder @@ -17,7 +18,7 @@ class NginxDockerFileBuilder extends AbstractFileBuilder { $projectNginxDockerfilePath = $config->getFilePath('projectNginxDockerfile'); - if (!$projectNginxDockerfilePath instanceof SpinnerFilePath) { + if (!$projectNginxDockerfilePath instanceof FilePath) { throw new \Exception('Project PHP-FPM Dockerfile not found'); } diff --git a/src/Classes/File/PHPDockerFileBuilder.php b/src/Classes/File/PHPDockerFileBuilder.php index 6583ca8..53605e8 100644 --- a/src/Classes/File/PHPDockerFileBuilder.php +++ b/src/Classes/File/PHPDockerFileBuilder.php @@ -6,6 +6,7 @@ namespace Loom\Spinner\Classes\File; use Loom\Spinner\Classes\Config\Config; use Loom\Spinner\Classes\File\Interface\DataPathInterface; +use Loom\Utility\FilePath\FilePath; use Symfony\Component\Console\Input\InputInterface; class PHPDockerFileBuilder extends AbstractFileBuilder @@ -17,7 +18,7 @@ class PHPDockerFileBuilder extends AbstractFileBuilder { $projectPhpFpmDockerfile = $config->getFilePath('projectPhpFpmDockerfile'); - if (!$projectPhpFpmDockerfile instanceof SpinnerFilePath) { + if (!$projectPhpFpmDockerfile instanceof FilePath) { throw new \Exception('Project PHP-FPM Dockerfile not found'); } @@ -34,13 +35,13 @@ class PHPDockerFileBuilder extends AbstractFileBuilder $this->content = str_replace('${PHP_VERSION}', (string) $this->config->getPhpVersion($input), $this->content); file_put_contents( - (new SpinnerFilePath(sprintf('data/environments/%s/php-fpm/opcache.ini', $input->getArgument('name'))))->getProvidedPath(), + (new FilePath(sprintf('data/environments/%s/php-fpm/opcache.ini', $input->getArgument('name'))))->getProvidedPath(), file_get_contents($this->config->getFilePaths()->get('opcacheIniTemplate')->getAbsolutePath()) ); if ($this->config->isDatabaseEnabled($input) && in_array($this->config->getDatabaseDriver($input), ['sqlite3', 'sqlite'])) { $this->addNewLine(); - $this->content .= file_get_contents((new SpinnerFilePath('config/php-fpm/Sqlite.Dockerfile'))->getAbsolutePath()); + $this->content .= file_get_contents((new FilePath('config/php-fpm/Sqlite.Dockerfile'))->getAbsolutePath()); } if ($this->config->isNodeEnabled($input)) { @@ -53,7 +54,7 @@ class PHPDockerFileBuilder extends AbstractFileBuilder $this->addNewLine(); $this->content .= file_get_contents($this->config->getFilePaths()->get('xdebugDockerfileTemplate')->getAbsolutePath()); file_put_contents( - (new SpinnerFilePath(sprintf('data/environments/%s/php-fpm/xdebug.ini', $input->getArgument('name'))))->getProvidedPath(), + (new FilePath(sprintf('data/environments/%s/php-fpm/xdebug.ini', $input->getArgument('name'))))->getProvidedPath(), file_get_contents($this->config->getFilePaths()->get('xdebugIniTemplate')->getAbsolutePath()) ); } diff --git a/src/Classes/File/SpinnerFilePath.php b/src/Classes/File/SpinnerFilePath.php deleted file mode 100644 index a95e8a7..0000000 --- a/src/Classes/File/SpinnerFilePath.php +++ /dev/null @@ -1,20 +0,0 @@ -path; - } -} \ No newline at end of file diff --git a/src/Command/AbstractSpinnerCommand.php b/src/Command/AbstractSpinnerCommand.php index dffa13e..9b8606c 100644 --- a/src/Command/AbstractSpinnerCommand.php +++ b/src/Command/AbstractSpinnerCommand.php @@ -6,7 +6,6 @@ namespace Loom\Spinner\Command; use Loom\Spinner\Classes\Collection\FilePathCollection; use Loom\Spinner\Classes\Config\Config; -use Loom\Spinner\Classes\File\SpinnerFilePath; use Loom\Spinner\Classes\OS\System; use Loom\Spinner\Command\Interface\ConsoleCommandInterface; use Loom\Utility\FilePath\FilePath; @@ -54,7 +53,7 @@ class AbstractSpinnerCommand extends Command implements ConsoleCommandInterface protected function buildDockerComposeCommand(string $command, bool $daemon = true): string { return sprintf( - 'cd %s && docker-compose --env-file=%s %s%s', + 'cd %s && docker compose --env-file=%s %s%s', $this->config->getFilePaths()->get('projectData')->getAbsolutePath(), $this->config->getFilePaths()->get('projectEnv')->getAbsolutePath(), $command, @@ -81,25 +80,26 @@ class AbstractSpinnerCommand extends Command implements ConsoleCommandInterface private function validateNameArgument(InputInterface $input): void { + var_dump('Validating name argument'); if ($input->hasArgument('name')) { $this->config->addFilePath( - new SpinnerFilePath(sprintf('data/environments/%s', $input->getArgument('name'))), + new FilePath(sprintf('data/environments/%s', $input->getArgument('name'))), 'projectData' ); $this->config->addFilePath( - new SpinnerFilePath(sprintf('data/environments/%s/.env', $input->getArgument('name'))), + new FilePath(sprintf('data/environments/%s/.env', $input->getArgument('name'))), 'projectEnv' ); $this->config->addFilePath( - new SpinnerFilePath(sprintf('data/environments/%s/docker-compose.yml', $input->getArgument('name'))), + new FilePath(sprintf('data/environments/%s/docker-compose.yml', $input->getArgument('name'))), 'projectDockerCompose' ); $this->config->addFilePath( - new SpinnerFilePath(sprintf('data/environments/%s/php-fpm/Dockerfile', $input->getArgument('name'))), + new FilePath(sprintf('data/environments/%s/php-fpm/Dockerfile', $input->getArgument('name'))), 'projectPhpFpmDockerfile' ); $this->config->addFilePath( - new SpinnerFilePath(sprintf('data/environments/%s/nginx/Dockerfile', $input->getArgument('name'))), + new FilePath(sprintf('data/environments/%s/nginx/Dockerfile', $input->getArgument('name'))), 'projectNginxDockerfile' ); $this->config->addFilePath( diff --git a/src/Command/SpinCommand.php b/src/Command/SpinCommand.php index c785541..f3d38e3 100644 --- a/src/Command/SpinCommand.php +++ b/src/Command/SpinCommand.php @@ -7,8 +7,8 @@ namespace Loom\Spinner\Command; use Loom\Spinner\Classes\File\DockerComposeFileBuilder; use Loom\Spinner\Classes\File\NginxDockerFileBuilder; use Loom\Spinner\Classes\File\PHPDockerFileBuilder; -use Loom\Spinner\Classes\File\SpinnerFilePath; use Loom\Spinner\Classes\OS\PortGenerator; +use Loom\Utility\FilePath\FilePath; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -131,7 +131,7 @@ class SpinCommand extends AbstractSpinnerCommand { $projectData = $this->config->getFilePaths()->get('projectData'); - if (!$projectData instanceof SpinnerFilePath) { + if (!$projectData instanceof FilePath) { throw new \Exception('Invalid project data directory provided.'); } @@ -145,7 +145,7 @@ class SpinCommand extends AbstractSpinnerCommand { $projectEnv = $this->config->getFilePaths()->get('projectEnv'); - if (!$projectEnv instanceof SpinnerFilePath) { + if (!$projectEnv instanceof FilePath) { throw new \Exception('Invalid project environment file provided.'); } @@ -192,7 +192,7 @@ class SpinCommand extends AbstractSpinnerCommand { $projectData = $this->config->getFilePaths()->get('projectData'); - if (!$projectData instanceof SpinnerFilePath) { + if (!$projectData instanceof FilePath) { throw new \Exception('Invalid project data directory provided.'); } @@ -208,7 +208,7 @@ class SpinCommand extends AbstractSpinnerCommand { $projectData = $this->config->getFilePaths()->get('projectData'); - if (!$projectData instanceof SpinnerFilePath) { + if (!$projectData instanceof FilePath) { throw new \Exception('Invalid project data directory provided.'); }