Test Failed
Pull Request — master (#67)
by
unknown
05:53
created

Migration::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2017
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace FastD\Console;
11
12
use FastD\Migration\Migrate;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Class Migration.
19
 */
20
class Migration extends Migrate
21
{
22
    public function configure()
23
    {
24
        parent::configure();
25
        $this->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Database default connection', 'default');
26
    }
27
28
    public function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $config = config()->get('database', []);
31
        $connection = $input->getOption('connection');
32
        if (!isset($config[$connection])) {
33
            throw new \RuntimeException(sprintf('Cannot found database "%s" config', $connection));
34
        }
35
36
        $this->config = $config[$connection];
37
        $this->config['dbname'] = $this->config['name'];
38
39
        $this->createConnection();
40
41
        return parent::execute($input, $output);
42
    }
43
}
44