Completed
Pull Request — 4.2 (#140)
by David
09:39 queued 04:42
created

GenerateCommand::execute()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 25
rs 8.8571
c 1
b 0
f 0
cc 2
eloc 12
nc 2
nop 2
1
<?php
2
namespace Mouf\Database\TDBM\Commands;
3
4
use Mouf\Database\TDBM\ConfigurationInterface;
5
use Mouf\Database\TDBM\TDBMService;
6
use Mouf\Utils\Log\Psr\MultiLogger;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Logger\ConsoleLogger;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class GenerateCommand extends Command
13
{
14
15
    /**
16
     * @var ConfigurationInterface
17
     */
18
    private $configuration;
19
20
    public function __construct(ConfigurationInterface $configuration)
21
    {
22
        parent::__construct();
23
        $this->configuration = $configuration;
24
    }
25
26
    protected function configure()
27
    {
28
        $this->setName('tdbm:generate')
29
            ->setDescription('Generates DAOs and beans.')
30
            ->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.')
31
        ;
32
    }
33
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        // TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans)
37
38
        $alteredConf = new AlteredConfiguration($this->configuration);
39
40
41
        $loggers = [ new ConsoleLogger($output) ];
42
43
        $logger = $alteredConf->getLogger();
44
        if ($logger) {
45
            $loggers[] = $logger;
46
        }
47
48
        $multiLogger = new MultiLogger($loggers);
49
50
        $alteredConf->setLogger($multiLogger);
51
52
        $multiLogger->notice('Starting regenerating DAOs and beans');
53
54
        $tdbmService = new TDBMService($this->configuration);
55
        $tdbmService->generateAllDaosAndBeans();
56
57
        $multiLogger->notice('Finished regenerating DAOs and beans');
58
    }
59
}
60