diff --git a/Command/InstallFromFolderCommand.php b/Command/InstallFromFolderCommand.php index 590953c..026f210 100644 --- a/Command/InstallFromFolderCommand.php +++ b/Command/InstallFromFolderCommand.php @@ -54,8 +54,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->note("Installing full version of FIAS from '{$folder}' folder"); $start = microtime(true); - $state = new ArrayState(); - $state = $state->setAndLockParameter(StateParameter::PATH_TO_EXTRACT_FOLDER, $folder); + $state = new ArrayState( + [ + StateParameter::PATH_TO_EXTRACT_FOLDER->value => $folder, + ] + ); $this->pipeline->run($state); $total = round(microtime(true) - $start, 4); diff --git a/Command/InstallParallelRunningCommand.php b/Command/InstallParallelRunningCommand.php index 87f1c42..fdb1e6a 100644 --- a/Command/InstallParallelRunningCommand.php +++ b/Command/InstallParallelRunningCommand.php @@ -5,12 +5,11 @@ namespace Liquetsoft\Fias\Symfony\LiquetsoftFiasBundle\Command; use Liquetsoft\Fias\Component\Pipeline\Pipe\Pipe; -use Liquetsoft\Fias\Component\Pipeline\State\ArrayState; -use Liquetsoft\Fias\Component\Pipeline\State\StateParameter; +use Liquetsoft\Fias\Component\Pipeline\State\State; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Serializer\SerializerInterface; /** * Команда для параллельных процессов, в которых идет установка ФИАС. @@ -19,8 +18,10 @@ */ final class InstallParallelRunningCommand extends Command { - public function __construct(private readonly Pipe $pipeline) - { + public function __construct( + private readonly Pipe $pipeline, + private readonly SerializerInterface $serializer, + ) { parent::__construct(); } @@ -32,7 +33,6 @@ protected function configure(): void $this ->setName('liquetsoft:fias:install_parallel_running') ->setDescription('Command for running one single thread of installation process') - ->addArgument('files', InputArgument::OPTIONAL, 'Json encoded list of files to process') ; } @@ -41,20 +41,13 @@ protected function configure(): void */ protected function execute(InputInterface $input, OutputInterface $output): int { - $files = $input->getArgument('files'); - if (\is_array($files)) { - $files = reset($files); + $stdIn = file_get_contents('php://stdin'); + if ($stdIn === false || $stdIn === '') { + return 1; } - if ($files !== null && $files !== '') { - $files = json_decode((string) $files, true); - } else { - $stdIn = file_get_contents('php://stdin'); - $files = $stdIn !== false ? json_decode($stdIn, true) : []; - } + $state = $this->serializer->deserialize($stdIn, State::class, 'json'); - $state = new ArrayState(); - $state->setAndLockParameter(StateParameter::FILES_TO_PROCEED, $files); $this->pipeline->run($state); return 0; diff --git a/Command/UpdateFromFolderCommand.php b/Command/UpdateFromFolderCommand.php index 62d60c1..6113753 100644 --- a/Command/UpdateFromFolderCommand.php +++ b/Command/UpdateFromFolderCommand.php @@ -53,8 +53,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->note("Updating FIAS from the '{$folder}' folder"); - $state = new ArrayState(); - $state = $state->setAndLockParameter(StateParameter::PATH_TO_EXTRACT_FOLDER, $folder); + $state = new ArrayState( + [ + StateParameter::PATH_TO_EXTRACT_FOLDER->value => $folder, + ] + ); $this->pipeline->run($state); $io->success("FIAS updated from the '{$folder}' folder"); diff --git a/Command/UpdateParallelRunningCommand.php b/Command/UpdateParallelRunningCommand.php index 1e1923f..b77670a 100644 --- a/Command/UpdateParallelRunningCommand.php +++ b/Command/UpdateParallelRunningCommand.php @@ -5,12 +5,11 @@ namespace Liquetsoft\Fias\Symfony\LiquetsoftFiasBundle\Command; use Liquetsoft\Fias\Component\Pipeline\Pipe\Pipe; -use Liquetsoft\Fias\Component\Pipeline\State\ArrayState; -use Liquetsoft\Fias\Component\Pipeline\State\StateParameter; +use Liquetsoft\Fias\Component\Pipeline\State\State; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Serializer\SerializerInterface; /** * Команда для параллельных процессов, в которых идет обновление ФИАС. @@ -19,8 +18,10 @@ */ final class UpdateParallelRunningCommand extends Command { - public function __construct(private readonly Pipe $pipeline) - { + public function __construct( + private readonly Pipe $pipeline, + private readonly SerializerInterface $serializer, + ) { parent::__construct(); } @@ -32,7 +33,6 @@ protected function configure(): void $this ->setName('liquetsoft:fias:update_parallel_running') ->setDescription('Command for running one single thread of updating process') - ->addArgument('files', InputArgument::OPTIONAL, 'Json encoded list of files to process') ; } @@ -41,20 +41,13 @@ protected function configure(): void */ protected function execute(InputInterface $input, OutputInterface $output): int { - $files = $input->getArgument('files'); - if (\is_array($files)) { - $files = reset($files); + $stdIn = file_get_contents('php://stdin'); + if ($stdIn === false || $stdIn === '') { + return 1; } - if ($files !== null && $files !== '') { - $files = json_decode((string) $files, true); - } else { - $stdIn = file_get_contents('php://stdin'); - $files = $stdIn !== false ? json_decode($stdIn, true) : []; - } + $state = $this->serializer->deserialize($stdIn, State::class, 'json'); - $state = new ArrayState(); - $state->setAndLockParameter(StateParameter::FILES_TO_PROCEED, $files); $this->pipeline->run($state); return 0; diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml index fa93eda..8ff4c9e 100644 --- a/Resources/config/services.yaml +++ b/Resources/config/services.yaml @@ -65,6 +65,16 @@ services: tags: - { name: 'serializer.normalizer' } + liquetsoft_fias.serializer.pipeline_state_normalizer: + class: Liquetsoft\Fias\Component\Serializer\FiasPipelineStateNormalizer + tags: + - { name: 'serializer.normalizer' } + + liquetsoft_fias.serializer.pipeline_state_denormalizer: + class: Liquetsoft\Fias\Component\Serializer\FiasPipelineStateDenormalizer + tags: + - { name: 'serializer.normalizer' } + liquetsoft_fias.serializer.compiled_denormalizer: class: Liquetsoft\Fias\Symfony\LiquetsoftFiasBundle\Serializer\CompiledEntitesDenormalizer tags: @@ -326,6 +336,7 @@ services: class: Liquetsoft\Fias\Symfony\LiquetsoftFiasBundle\Command\InstallParallelRunningCommand arguments: - '@liquetsoft_fias.pipe.install_parallel_running' + - '@serializer' tags: - { name: 'console.command' } @@ -354,6 +365,7 @@ services: class: Liquetsoft\Fias\Symfony\LiquetsoftFiasBundle\Command\UpdateParallelRunningCommand arguments: - '@liquetsoft_fias.pipe.update_parallel_running' + - '@serializer' tags: - { name: 'console.command' } diff --git a/Serializer/FiasSerializer.php b/Serializer/FiasSerializer.php index 71cc450..a2639fc 100644 --- a/Serializer/FiasSerializer.php +++ b/Serializer/FiasSerializer.php @@ -5,6 +5,8 @@ namespace Liquetsoft\Fias\Symfony\LiquetsoftFiasBundle\Serializer; use Liquetsoft\Fias\Component\Serializer\FiasNameConverter; +use Liquetsoft\Fias\Component\Serializer\FiasPipelineStateDenormalizer; +use Liquetsoft\Fias\Component\Serializer\FiasPipelineStateNormalizer; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Component\Serializer\Encoder\EncoderInterface; @@ -31,6 +33,8 @@ public function __construct(?array $normalizers = null, ?array $encoders = null) $normalizers = [ new CompiledEntitesDenormalizer(), new FiasUuidNormalizer(), + new FiasPipelineStateNormalizer(), + new FiasPipelineStateDenormalizer(), new DateTimeNormalizer(), new ObjectNormalizer( nameConverter: new FiasNameConverter(), diff --git a/Tests/Pipeline/InstallPipelineTest.php b/Tests/Pipeline/InstallPipelineTest.php index 1cf4ebd..73bf105 100644 --- a/Tests/Pipeline/InstallPipelineTest.php +++ b/Tests/Pipeline/InstallPipelineTest.php @@ -63,12 +63,15 @@ public function testInstall(): void $versionEntity->setFullurl($versionFullUrl); $versionEntity->setDeltaurl($versionDeltaUrl); - $state = new ArrayState(); - $state->setAndLockParameter(StateParameter::PATH_TO_DOWNLOAD_FILE, $testArchive); - $state->setAndLockParameter(StateParameter::PATH_TO_EXTRACT_FOLDER, $testDir); - $state->setAndLockParameter(StateParameter::FIAS_NEXT_VERSION_NUMBER, $version); - $state->setAndLockParameter(StateParameter::FIAS_NEXT_VERSION_FULL_URL, $versionFullUrl); - $state->setAndLockParameter(StateParameter::FIAS_NEXT_VERSION_DELTA_URL, $versionDeltaUrl); + $state = new ArrayState( + [ + StateParameter::PATH_TO_DOWNLOAD_FILE->value => $testArchive, + StateParameter::PATH_TO_EXTRACT_FOLDER->value => $testDir, + StateParameter::FIAS_NEXT_VERSION_NUMBER->value => $version, + StateParameter::FIAS_NEXT_VERSION_FULL_URL->value => $versionFullUrl, + StateParameter::FIAS_NEXT_VERSION_DELTA_URL->value => $versionDeltaUrl, + ] + ); $pipeline = $this->createPipeLine(); $pipeline->run($state); diff --git a/Tests/Pipeline/UpdatePipelineTest.php b/Tests/Pipeline/UpdatePipelineTest.php index c587bd9..9ddd9dc 100644 --- a/Tests/Pipeline/UpdatePipelineTest.php +++ b/Tests/Pipeline/UpdatePipelineTest.php @@ -63,12 +63,15 @@ public function testUpdate(): void $versionEntity->setFullurl($versionFullUrl); $versionEntity->setDeltaurl($versionDeltaUrl); - $state = new ArrayState(); - $state->setAndLockParameter(StateParameter::PATH_TO_DOWNLOAD_FILE, $testArchive); - $state->setAndLockParameter(StateParameter::PATH_TO_EXTRACT_FOLDER, $testDir); - $state->setAndLockParameter(StateParameter::FIAS_NEXT_VERSION_NUMBER, $version); - $state->setAndLockParameter(StateParameter::FIAS_NEXT_VERSION_FULL_URL, $versionFullUrl); - $state->setAndLockParameter(StateParameter::FIAS_NEXT_VERSION_DELTA_URL, $versionDeltaUrl); + $state = new ArrayState( + [ + StateParameter::PATH_TO_DOWNLOAD_FILE->value => $testArchive, + StateParameter::PATH_TO_EXTRACT_FOLDER->value => $testDir, + StateParameter::FIAS_NEXT_VERSION_NUMBER->value => $version, + StateParameter::FIAS_NEXT_VERSION_FULL_URL->value => $versionFullUrl, + StateParameter::FIAS_NEXT_VERSION_DELTA_URL->value => $versionDeltaUrl, + ] + ); $pipeline = $this->createPipeLine(); $pipeline->run($state); diff --git a/composer.json b/composer.json index aba14f8..c33d7af 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "license": "MIT", "require": { "php": ">=8.2", - "liquetsoft/fias-component": "^13.1", + "liquetsoft/fias-component": "dev-master", "symfony/uid": "^5.0|^6.0|^7.0", "symfony/framework-bundle": "^5.0|^6.0|^7.0", "symfony/http-client": "^5.0|^6.0|^7.0",