|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Shapin\Datagen\Bridge\Symfony\Bundle\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Shapin\Datagen\Datagen; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
13
|
|
|
|
|
14
|
|
|
class LoadCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
private $datagen; |
|
17
|
|
|
|
|
18
|
2 |
|
public function __construct(Datagen $datagen) |
|
19
|
|
|
{ |
|
20
|
2 |
|
$this->datagen = $datagen; |
|
21
|
|
|
|
|
22
|
2 |
|
parent::__construct(); |
|
23
|
2 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
2 |
|
protected function configure() |
|
29
|
|
|
{ |
|
30
|
|
|
$this |
|
31
|
2 |
|
->setName('shapin:datagen:load') |
|
32
|
2 |
|
->setDescription('Load the world!') |
|
33
|
2 |
|
->addOption('group', 'g', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Which groups should be loaded? (default: all)') |
|
34
|
2 |
|
->addOption('exclude-group', 'G', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Which groups should be excluded? (default: none)') |
|
35
|
2 |
|
->addOption('dbal-schema-only', null, InputOption::VALUE_NONE, '[DBAL] Load only schema.') |
|
36
|
2 |
|
->addOption('dbal-fixtures-only', null, InputOption::VALUE_NONE, '[DBAL] Load only fixtures.') |
|
37
|
2 |
|
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Load only fixtures related to given processor.') |
|
38
|
|
|
; |
|
39
|
2 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
45
|
|
|
{ |
|
46
|
2 |
|
$io = new SymfonyStyle($input, $output); |
|
47
|
|
|
|
|
48
|
2 |
|
$io->title('Load the world! \o/'); |
|
49
|
|
|
|
|
50
|
2 |
|
$groups = $input->getOption('group'); |
|
51
|
2 |
|
$excludeGroups = $input->getOption('exclude-group'); |
|
52
|
|
|
|
|
53
|
|
|
$options = [ |
|
54
|
|
|
'dbal' => [ |
|
55
|
2 |
|
'schema_only' => $input->getOption('dbal-schema-only'), |
|
56
|
2 |
|
'fixtures_only' => $input->getOption('dbal-fixtures-only'), |
|
57
|
|
|
], |
|
58
|
|
|
]; |
|
59
|
2 |
|
if (null !== $processor = $input->getOption('processor')) { |
|
60
|
|
|
$options['processor'] = $processor; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
$this->datagen->load($groups, $excludeGroups, $options); |
|
64
|
|
|
|
|
65
|
2 |
|
$io->success('Job DONE!'); |
|
66
|
|
|
|
|
67
|
2 |
|
return 0; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|