Skip to content

Commit 63591fb

Browse files
authored
Partial unpacking (#98)
1 parent c2a9180 commit 63591fb

11 files changed

+258
-112
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"require": {
88
"php": ">=8.2",
9-
"liquetsoft/fias-component": "^13.1",
9+
"liquetsoft/fias-component": "^14.0",
1010
"illuminate/database": "^8.0|^9.0|^10.0|^11.0",
1111
"illuminate/http": "^8.0|^9.0|^10.0|^11.0",
1212
"laravel/framework": "^8.0|^9.0|^10.0|^11.0"

src/Command/DownloadCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Liquetsoft\Fias\Component\FiasInformer\FiasInformer;
1010
use Liquetsoft\Fias\Component\FiasInformer\FiasInformerResponse;
1111
use Liquetsoft\Fias\Component\Unpacker\Unpacker;
12-
use Marvin255\FileSystemHelper\FileSystemHelperInterface;
12+
use Marvin255\FileSystemHelper\FileSystemHelper;
1313

1414
/**
1515
* Консольная команда, которая загружает указанную версию ФИАС в указанную папку.
@@ -26,7 +26,7 @@ public function __construct(
2626
private readonly Downloader $downloader,
2727
private readonly Unpacker $unpacker,
2828
private readonly FiasInformer $informer,
29-
private readonly FileSystemHelperInterface $fs,
29+
private readonly FileSystemHelper $fs,
3030
) {
3131
parent::__construct();
3232
}

src/Command/InstallFromFolderCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ public function handle(): void
4141
$this->info("Installing full version of FIAS from '{$folder}' folder");
4242
$start = microtime(true);
4343

44-
$state = new ArrayState();
45-
$state->setAndLockParameter(StateParameter::PATH_TO_EXTRACT_FOLDER, $folder);
44+
$state = new ArrayState(
45+
[
46+
StateParameter::PATH_TO_SOURCE->value => $folder,
47+
]
48+
);
4649

4750
try {
4851
$this->pipeline->run($state);

src/Command/InstallParallelRunningCommand.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,44 @@
77
use Illuminate\Console\Command;
88
use Illuminate\Foundation\Application;
99
use Liquetsoft\Fias\Component\Pipeline\Pipe\Pipe;
10-
use Liquetsoft\Fias\Component\Pipeline\State\ArrayState;
11-
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
10+
use Liquetsoft\Fias\Component\Pipeline\State\State;
11+
use Symfony\Component\Serializer\SerializerInterface;
1212

1313
/**
1414
* Консольная команда, которая является одним из параллельных процессов установки ФИАС.
1515
*/
1616
final class InstallParallelRunningCommand extends Command
1717
{
18-
protected $signature = 'liquetsoft:fias:install_parallel_running {files?}';
18+
protected $signature = 'liquetsoft:fias:install_parallel_running';
1919

2020
protected $description = 'Command for running parallel installation.';
2121

2222
private readonly Pipe $pipeline;
2323

24+
private readonly SerializerInterface $serializer;
25+
2426
/**
2527
* В конструкторе передаем ссылку на пайплайн установки.
2628
*/
2729
public function __construct(Application $app)
2830
{
2931
parent::__construct();
3032
$this->pipeline = $app->get('liquetsoft_fias.pipe.install_parallel_running');
33+
$this->serializer = $app->get('liquetsoft_fias.serializer.serializer');
3134
}
3235

3336
/**
3437
* Запуск команды на исполнение.
3538
*/
3639
public function handle(): void
3740
{
38-
$files = $this->argument('files');
39-
if (\is_array($files)) {
40-
$files = reset($files);
41+
$stdIn = file_get_contents('php://stdin');
42+
if ($stdIn === false || $stdIn === '') {
43+
return;
4144
}
4245

43-
if ($files !== false && $files !== null && $files !== '') {
44-
$files = json_decode((string) $files, true);
45-
} else {
46-
$stdIn = file_get_contents('php://stdin');
47-
if ($stdIn !== false && $stdIn !== '') {
48-
$files = json_decode($stdIn, true);
49-
}
50-
}
46+
$state = $this->serializer->deserialize($stdIn, State::class, 'json');
5147

52-
$state = new ArrayState();
53-
$state->setAndLockParameter(StateParameter::FILES_TO_PROCEED, $files);
5448
$this->pipeline->run($state);
5549
}
5650
}

src/Command/UpdateFromFolderCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ public function handle(): void
4141
$this->info("Updating FIAS version from '{$folder}' folder");
4242
$start = microtime(true);
4343

44-
$state = new ArrayState();
45-
$state->setAndLockParameter(StateParameter::PATH_TO_EXTRACT_FOLDER, $folder);
44+
$state = new ArrayState(
45+
[
46+
StateParameter::PATH_TO_SOURCE->value => $folder,
47+
]
48+
);
4649

4750
try {
4851
$this->pipeline->run($state);

src/Command/UpdateParallelRunningCommand.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,30 @@
88
use Illuminate\Foundation\Application;
99
use Liquetsoft\Fias\Component\Exception\PipeException;
1010
use Liquetsoft\Fias\Component\Pipeline\Pipe\Pipe;
11-
use Liquetsoft\Fias\Component\Pipeline\State\ArrayState;
12-
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
11+
use Liquetsoft\Fias\Component\Pipeline\State\State;
12+
use Symfony\Component\Serializer\SerializerInterface;
1313

1414
/**
1515
* Консольная команда, которая является одним из параллельных процессов обновления ФИАС.
1616
*/
1717
final class UpdateParallelRunningCommand extends Command
1818
{
19-
protected $signature = 'liquetsoft:fias:update_parallel_running {files?}';
19+
protected $signature = 'liquetsoft:fias:update_parallel_running';
2020

2121
protected $description = 'Command for running parallel update.';
2222

2323
private readonly Pipe $pipeline;
2424

25+
private readonly SerializerInterface $serializer;
26+
2527
/**
2628
* В конструкторе передаем ссылку на пайплайн установки.
2729
*/
2830
public function __construct(Application $app)
2931
{
3032
parent::__construct();
3133
$this->pipeline = $app->get('liquetsoft_fias.pipe.update_parallel_running');
34+
$this->serializer = $app->get('liquetsoft_fias.serializer.serializer');
3235
}
3336

3437
/**
@@ -38,22 +41,13 @@ public function __construct(Application $app)
3841
*/
3942
public function handle(): void
4043
{
41-
$files = $this->argument('files');
42-
if (\is_array($files)) {
43-
$files = reset($files);
44+
$stdIn = file_get_contents('php://stdin');
45+
if ($stdIn === false || $stdIn === '') {
46+
return;
4447
}
4548

46-
if ($files !== false && $files !== null && $files !== '') {
47-
$files = json_decode((string) $files, true);
48-
} else {
49-
$stdIn = file_get_contents('php://stdin');
50-
if ($stdIn !== false && $stdIn !== '') {
51-
$files = json_decode($stdIn, true);
52-
}
53-
}
49+
$state = $this->serializer->deserialize($stdIn, State::class, 'json');
5450

55-
$state = new ArrayState();
56-
$state->setAndLockParameter(StateParameter::FILES_TO_PROCEED, $files);
5751
$this->pipeline->run($state);
5852
}
5953
}

0 commit comments

Comments
 (0)