From 2ca755ee28cd84f0807f5d4c219681bbae74c7dd Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 3 Aug 2024 12:53:20 +0100 Subject: [PATCH] Refactor Actions to Commands --- .../CreateFinalConfigurationDataCommand.php} | 6 +++--- .../CreateListOfFilesToGenerateCommand.php} | 6 +++--- .../GenerateConfigurationFilesCommand.php} | 6 +++--- .../ValidateConfigurationDataCommand.php} | 7 ++++--- src/Console/Command/GenerateCommand.php | 18 +++++++++--------- 5 files changed, 22 insertions(+), 21 deletions(-) rename src/{Action/CreateFinalConfigurationData.php => Command/CreateFinalConfigurationDataCommand.php} (95%) rename src/{Action/CreateListOfFilesToGenerate.php => Command/CreateListOfFilesToGenerateCommand.php} (98%) rename src/{Action/GenerateConfigurationFiles.php => Command/GenerateConfigurationFilesCommand.php} (94%) rename src/{Action/ValidateConfigurationData.php => Command/ValidateConfigurationDataCommand.php} (88%) diff --git a/src/Action/CreateFinalConfigurationData.php b/src/Command/CreateFinalConfigurationDataCommand.php similarity index 95% rename from src/Action/CreateFinalConfigurationData.php rename to src/Command/CreateFinalConfigurationDataCommand.php index 074c8ac..264da31 100644 --- a/src/Action/CreateFinalConfigurationData.php +++ b/src/Command/CreateFinalConfigurationDataCommand.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace App\Action; +namespace App\Command; use Illuminate\Support\Arr; use Symfony\Component\Yaml\Yaml; -final class CreateFinalConfigurationData +final class CreateFinalConfigurationDataCommand { - public function handle(string $configFile, \Closure $next) + public function execute(string $configFile, \Closure $next) { // Perform some initial checks before the defaults are merged. $configurationData = Yaml::parseFile(filename: $configFile); diff --git a/src/Action/CreateListOfFilesToGenerate.php b/src/Command/CreateListOfFilesToGenerateCommand.php similarity index 98% rename from src/Action/CreateListOfFilesToGenerate.php rename to src/Command/CreateListOfFilesToGenerateCommand.php index 5528335..bb236df 100644 --- a/src/Action/CreateListOfFilesToGenerate.php +++ b/src/Command/CreateListOfFilesToGenerateCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Action; +namespace App\Command; use App\DataTransferObject\ConfigDto; use App\DataTransferObject\TemplateFile; @@ -11,9 +11,9 @@ use App\Enum\WebServer; use Illuminate\Support\Arr; use Illuminate\Support\Collection; -final class CreateListOfFilesToGenerate +final class CreateListOfFilesToGenerateCommand { - public function handle(array $configurationDataAndDto, \Closure $next) + public function execute(array $configurationDataAndDto, \Closure $next) { /** * @var ConfigDto $configDto, diff --git a/src/Action/GenerateConfigurationFiles.php b/src/Command/GenerateConfigurationFilesCommand.php similarity index 94% rename from src/Action/GenerateConfigurationFiles.php rename to src/Command/GenerateConfigurationFilesCommand.php index e8fcd73..bd4b5eb 100644 --- a/src/Action/GenerateConfigurationFiles.php +++ b/src/Command/GenerateConfigurationFilesCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Action; +namespace App\Command; use App\DataTransferObject\ConfigDto; use App\DataTransferObject\TemplateFile; @@ -10,7 +10,7 @@ use Illuminate\Support\Collection; use Symfony\Component\Filesystem\Filesystem; use Twig\Environment; -final class GenerateConfigurationFiles +final class GenerateConfigurationFilesCommand { public function __construct( private Filesystem $filesystem, @@ -20,7 +20,7 @@ final class GenerateConfigurationFiles ) { } - public function handle(array $filesToGenerateAndConfigurationData, \Closure $next) + public function execute(array $filesToGenerateAndConfigurationData, \Closure $next) { /** * @var Collection $filesToGenerate diff --git a/src/Action/ValidateConfigurationData.php b/src/Command/ValidateConfigurationDataCommand.php similarity index 88% rename from src/Action/ValidateConfigurationData.php rename to src/Command/ValidateConfigurationDataCommand.php index 3babd2e..8db2f80 100644 --- a/src/Action/ValidateConfigurationData.php +++ b/src/Command/ValidateConfigurationDataCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Action; +namespace App\Command; use App\DataTransferObject\ConfigDto; use Symfony\Component\Serializer\Encoder\JsonEncoder; @@ -11,9 +11,10 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; use Symfony\Component\Validator\Validation; -final class ValidateConfigurationData +final class ValidateConfigurationDataCommand { - public function handle(array $configurationData, \Closure $next) { + public function execute(array $configurationData, \Closure $next) + { // Convert the input to a configuration data object. $normalizer = new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter()); $serializer = new Serializer([$normalizer], [new JsonEncoder()]); diff --git a/src/Console/Command/GenerateCommand.php b/src/Console/Command/GenerateCommand.php index eb7b25d..25482a3 100644 --- a/src/Console/Command/GenerateCommand.php +++ b/src/Console/Command/GenerateCommand.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace App\Console\Command; -use App\Action\CreateFinalConfigurationData; -use App\Action\CreateListOfFilesToGenerate; -use App\Action\GenerateConfigurationFiles; -use App\Action\ValidateConfigurationData; +use App\Command\CreateFinalConfigurationDataCommand; +use App\Command\CreateListOfFilesToGenerateCommand; +use App\Command\GenerateConfigurationFilesCommand; +use App\Command\ValidateConfigurationDataCommand; use App\DataTransferObject\ConfigDto; use App\DataTransferObject\TemplateFile; use Illuminate\Pipeline\Pipeline; @@ -42,7 +42,6 @@ class GenerateCommand extends Command shortcut: ['c'], mode: InputOption::VALUE_REQUIRED, description: 'The path to the project\'s build.yaml file', - default: 'build.yaml', ) ->addOption( name: 'output-dir', @@ -68,10 +67,10 @@ class GenerateCommand extends Command $isDryRun = $input->getOption(name: 'dry-run'); $pipelines = [ - new CreateFinalConfigurationData(), - new ValidateConfigurationData(), - new CreateListOfFilesToGenerate(), - new GenerateConfigurationFiles( + new CreateFinalConfigurationDataCommand(), + new ValidateConfigurationDataCommand(), + new CreateListOfFilesToGenerateCommand(), + new GenerateConfigurationFilesCommand( $this->filesystem, $this->twig, $outputDir, @@ -85,6 +84,7 @@ class GenerateCommand extends Command */ [$configurationData, $generatedFiles] = (new Pipeline()) ->send($configFile) + ->via('execute') ->through($pipelines) ->thenReturn();