mirror of
https://github.com/opdavies/build-configs.git
synced 2025-03-22 20:58:22 +00:00
Refactor Actions to Commands
This commit is contained in:
parent
a83c51bbcd
commit
2ca755ee28
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Action;
|
namespace App\Command;
|
||||||
|
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
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.
|
// Perform some initial checks before the defaults are merged.
|
||||||
$configurationData = Yaml::parseFile(filename: $configFile);
|
$configurationData = Yaml::parseFile(filename: $configFile);
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Action;
|
namespace App\Command;
|
||||||
|
|
||||||
use App\DataTransferObject\ConfigDto;
|
use App\DataTransferObject\ConfigDto;
|
||||||
use App\DataTransferObject\TemplateFile;
|
use App\DataTransferObject\TemplateFile;
|
||||||
|
@ -11,9 +11,9 @@ use App\Enum\WebServer;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
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,
|
* @var ConfigDto $configDto,
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Action;
|
namespace App\Command;
|
||||||
|
|
||||||
use App\DataTransferObject\ConfigDto;
|
use App\DataTransferObject\ConfigDto;
|
||||||
use App\DataTransferObject\TemplateFile;
|
use App\DataTransferObject\TemplateFile;
|
||||||
|
@ -10,7 +10,7 @@ use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
|
|
||||||
final class GenerateConfigurationFiles
|
final class GenerateConfigurationFilesCommand
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private Filesystem $filesystem,
|
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
|
* @var Collection<int,TemplateFile> $filesToGenerate
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Action;
|
namespace App\Command;
|
||||||
|
|
||||||
use App\DataTransferObject\ConfigDto;
|
use App\DataTransferObject\ConfigDto;
|
||||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||||
|
@ -11,9 +11,10 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||||
use Symfony\Component\Serializer\Serializer;
|
use Symfony\Component\Serializer\Serializer;
|
||||||
use Symfony\Component\Validator\Validation;
|
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.
|
// Convert the input to a configuration data object.
|
||||||
$normalizer = new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter());
|
$normalizer = new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter());
|
||||||
$serializer = new Serializer([$normalizer], [new JsonEncoder()]);
|
$serializer = new Serializer([$normalizer], [new JsonEncoder()]);
|
|
@ -4,10 +4,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Console\Command;
|
namespace App\Console\Command;
|
||||||
|
|
||||||
use App\Action\CreateFinalConfigurationData;
|
use App\Command\CreateFinalConfigurationDataCommand;
|
||||||
use App\Action\CreateListOfFilesToGenerate;
|
use App\Command\CreateListOfFilesToGenerateCommand;
|
||||||
use App\Action\GenerateConfigurationFiles;
|
use App\Command\GenerateConfigurationFilesCommand;
|
||||||
use App\Action\ValidateConfigurationData;
|
use App\Command\ValidateConfigurationDataCommand;
|
||||||
use App\DataTransferObject\ConfigDto;
|
use App\DataTransferObject\ConfigDto;
|
||||||
use App\DataTransferObject\TemplateFile;
|
use App\DataTransferObject\TemplateFile;
|
||||||
use Illuminate\Pipeline\Pipeline;
|
use Illuminate\Pipeline\Pipeline;
|
||||||
|
@ -42,7 +42,6 @@ class GenerateCommand extends Command
|
||||||
shortcut: ['c'],
|
shortcut: ['c'],
|
||||||
mode: InputOption::VALUE_REQUIRED,
|
mode: InputOption::VALUE_REQUIRED,
|
||||||
description: 'The path to the project\'s build.yaml file',
|
description: 'The path to the project\'s build.yaml file',
|
||||||
default: 'build.yaml',
|
|
||||||
)
|
)
|
||||||
->addOption(
|
->addOption(
|
||||||
name: 'output-dir',
|
name: 'output-dir',
|
||||||
|
@ -68,10 +67,10 @@ class GenerateCommand extends Command
|
||||||
$isDryRun = $input->getOption(name: 'dry-run');
|
$isDryRun = $input->getOption(name: 'dry-run');
|
||||||
|
|
||||||
$pipelines = [
|
$pipelines = [
|
||||||
new CreateFinalConfigurationData(),
|
new CreateFinalConfigurationDataCommand(),
|
||||||
new ValidateConfigurationData(),
|
new ValidateConfigurationDataCommand(),
|
||||||
new CreateListOfFilesToGenerate(),
|
new CreateListOfFilesToGenerateCommand(),
|
||||||
new GenerateConfigurationFiles(
|
new GenerateConfigurationFilesCommand(
|
||||||
$this->filesystem,
|
$this->filesystem,
|
||||||
$this->twig,
|
$this->twig,
|
||||||
$outputDir,
|
$outputDir,
|
||||||
|
@ -85,6 +84,7 @@ class GenerateCommand extends Command
|
||||||
*/
|
*/
|
||||||
[$configurationData, $generatedFiles] = (new Pipeline())
|
[$configurationData, $generatedFiles] = (new Pipeline())
|
||||||
->send($configFile)
|
->send($configFile)
|
||||||
|
->via('execute')
|
||||||
->through($pipelines)
|
->through($pipelines)
|
||||||
->thenReturn();
|
->thenReturn();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue