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