-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathGenerateCommand.php
More file actions
72 lines (55 loc) · 2.08 KB
/
GenerateCommand.php
File metadata and controls
72 lines (55 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace TheCodingMachine\TDBM\Commands;
use Symfony\Component\Console\Input\InputOption;
use TheCodingMachine\TDBM\ConfigurationInterface;
use TheCodingMachine\TDBM\TDBMService;
use Mouf\Utils\Log\Psr\MultiLogger;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
class GenerateCommand extends Command
{
/**
* @var ConfigurationInterface
*/
private $configuration;
public function __construct(ConfigurationInterface $configuration)
{
parent::__construct();
$this->configuration = $configuration;
}
protected function configure(): void
{
$this->setName('tdbm:generate')
->setDescription('Generates DAOs and beans.')
->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.')
->addOption(
'from-lock',
null,
InputOption::VALUE_OPTIONAL,
'Load the schema from the lock file instead of database',
false
)
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans)
$alteredConf = new AlteredConfiguration($this->configuration);
$fromLock = (bool) $input->getOption('from-lock');
$loggers = [ new ConsoleLogger($output) ];
$logger = $alteredConf->getLogger();
if ($logger) {
$loggers[] = $logger;
}
$multiLogger = new MultiLogger($loggers);
$alteredConf->setLogger($multiLogger);
$multiLogger->notice('Starting regenerating DAOs and beans');
$tdbmService = new TDBMService($this->configuration);
$tdbmService->generateAllDaosAndBeans($fromLock);
$multiLogger->notice('Finished regenerating DAOs and beans');
return 0;
}
}