mirror of
https://github.com/opdavies/build-configs.git
synced 2025-01-22 18:27:31 +00:00
Refactor Actions to Commands
This commit is contained in:
parent
a83c51bbcd
commit
2ca755ee28
|
@ -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);
|
|
@ -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,
|
|
@ -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<int,TemplateFile> $filesToGenerate
|
|
@ -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()]);
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue