1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\DwhBundle\Command; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use InvalidArgumentException; |
9
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire; |
15
|
|
|
use VideoGamesRecords\DwhBundle\Contracts\DwhInterface; |
16
|
|
|
use VideoGamesRecords\DwhBundle\Manager\TableManager; |
17
|
|
|
|
18
|
|
|
#[AsCommand( |
19
|
|
|
name: 'vgr-dwh:table', |
20
|
|
|
description: 'Command to update table' |
21
|
|
|
)] |
22
|
|
|
class TableCommand extends Command implements DwhInterface |
23
|
|
|
{ |
24
|
|
|
private TableManager $tableManager; |
25
|
|
|
|
26
|
|
|
public function __construct( |
27
|
|
|
#[Autowire(service: 'vgr.dwh.manager.table')] |
28
|
|
|
TableManager $tableManager |
29
|
|
|
) { |
30
|
|
|
$this->tableManager = $tableManager; |
31
|
|
|
parent::__construct(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function configure(): void |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->addArgument( |
38
|
|
|
'type', |
39
|
|
|
InputArgument::REQUIRED, |
40
|
|
|
'Strategy type' |
41
|
|
|
) |
42
|
|
|
->addArgument( |
43
|
|
|
'function', |
44
|
|
|
InputArgument::REQUIRED, |
45
|
|
|
'Call function' |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param InputInterface $input |
51
|
|
|
* @param OutputInterface $output |
52
|
|
|
* @return int |
53
|
|
|
* @throws Exception |
54
|
|
|
*/ |
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
56
|
|
|
{ |
57
|
|
|
$type = $input->getArgument('type'); |
58
|
|
|
$function = $input->getArgument('function'); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
if (!array_key_exists($type, self::COMMAND_TYPES)) { |
62
|
|
|
throw new InvalidArgumentException(sprintf('type [%s] is invalid', $type)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (!array_key_exists($function, self::COMMAND_FUNCTIONS)) { |
66
|
|
|
throw new InvalidArgumentException(sprintf('function [%s] is invalid', $function)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->tableManager->getStrategy($type)->$function(); |
70
|
|
|
return Command::SUCCESS; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|