Add default path setup and file helpers

This commit is contained in:
Daniel Winning 2025-04-12 15:14:28 +01:00
parent 524ed9f87d
commit 940fbc1234
7 changed files with 131 additions and 18 deletions

38
config/docker-compose.yml Normal file
View file

@ -0,0 +1,38 @@
version: "3.9"
services:
nginx:
build:
context: ./nginx
ports:
- ${NGINX_PORT}:80
volumes:
- ${PROJECT_DIRECTORY}:/var/www/html:cached
- ./nginx/conf.d:/etc/nginx/conf.d
php:
build:
context: ./php-fpm
working_dir: /var/www/html
extra_hosts:
- host.docker.internal:host-gateway
volumes:
- ${PROJECT_DIRECTORY}:/var/www/html:cached
ports:
- ${PHP_PORT}:9003
database:
image: mysql:8.0
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
ports:
- ${MYSQL_PORT}:3306
expose:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: docker
volumes:
- ./data/${PROJECT_NAME}/mysql:/var/lib/mysql:cached
cache:
image: redis:latest
ports:
- ${REDIS_PORT}:6379
volumes:
- ./data/${PROJECT_NAME}/redis:/data:cached

View file

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Loom\Spinner\Classes\Collection;
use Loom\Spinner\Classes\File\SpinnerFilePath;
use Loom\Utility\Collection\AbstractCollection;
class FilePathCollection extends AbstractCollection
{
public function __construct(array $items = [])
{
$items = array_filter($items, function ($item) {
return $item instanceof SpinnerFilePath;
});
parent::__construct($items);
}
public function get(string $key): ?SpinnerFilePath
{
return $this->items[$key] ?? null;
}
}

View file

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Loom\Spinner\Classes\File;
use Loom\Utility\FilePath\FilePath;
class SpinnerFilePath extends FilePath
{
public function __construct(string $projectPath)
{
parent::__construct(sprintf('%s%s%s', dirname(__DIR__, 3), DIRECTORY_SEPARATOR, $projectPath));
}
}

View file

@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Loom\Spinner\Helper; namespace Loom\Spinner\Classes\OS;
class System class System
{ {

View file

@ -4,26 +4,66 @@ declare(strict_types=1);
namespace Loom\Spinner\Command; namespace Loom\Spinner\Command;
use Loom\Spinner\Helper\System; 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;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
class AbstractSpinnerCommand extends Command class AbstractSpinnerCommand extends Command implements ConsoleCommandInterface
{ {
protected SymfonyStyle $style; protected SymfonyStyle $style;
protected System $system; protected System $system;
protected FilePathCollection $filePaths;
protected string $rootDirectory;
public function __construct() public function __construct()
{ {
$this->rootDirectory = dirname(__DIR__, 2);
$this->system = new System(); $this->system = new System();
$this->setFilePaths();
parent::__construct(); parent::__construct();
} }
protected function setStyle(InputInterface $input, OutputInterface $output): void 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
{ {
$this->style = new SymfonyStyle($input, $output); $this->style = new SymfonyStyle($input, $output);
} }
private function setFilePaths(): void
{
$this->filePaths = new FilePathCollection([
'config' => new SpinnerFilePath('config'),
]);
}
} }

View file

@ -0,0 +1,8 @@
<?php
namespace Loom\Spinner\Command\Interface;
interface ConsoleCommandInterface
{
public const string DOCKER_COMPOSE_COMMAND = '';
}

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Loom\Spinner\Command; namespace Loom\Spinner\Command;
use Loom\Utility\FilePath\FilePath;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@ -23,19 +22,7 @@ class SpinCommand extends AbstractSpinnerCommand
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$this->setStyle($input, $output); if (!parent::execute($input, $output)) {
$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;
}
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; return Command::FAILURE;
} }