1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Bluz PHP Team |
4
|
|
|
* @link https://github.com/bluzphp/bluzman |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Bluzman\Command\Db; |
8
|
|
|
|
9
|
|
|
use Bluzman\Command\AbstractCommand; |
10
|
|
|
use Phinx\Console\PhinxApplication; |
11
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* AbstractDbCommand |
17
|
|
|
* |
18
|
|
|
* @package Bluzman\Command\Db |
19
|
|
|
* @author Anton Shevchuk |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractDbCommand extends AbstractCommand |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param InputInterface $input |
25
|
|
|
* @param OutputInterface $output |
26
|
|
|
* @return int|null|void |
27
|
|
|
*/ |
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
$commandName = substr($this->getName(), 3); |
31
|
|
|
$arguments = $this->getDefinition()->getArguments(); |
32
|
|
|
|
33
|
|
|
$phinx = new PhinxApplication(); |
34
|
|
|
$command = $phinx->find($commandName); |
35
|
|
|
|
36
|
|
|
$phinxArguments = []; |
37
|
|
|
|
38
|
|
|
foreach ($arguments as $name => $argumentInput) { |
39
|
|
|
if ($input->getArgument($name)) { |
40
|
|
|
$phinxArguments[$name] = $input->getArgument($name); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$phinxArguments['command'] = $commandName; |
45
|
|
|
$phinxArguments['--configuration'] = PATH_APPLICATION .DS. 'configs' .DS. 'phinx.php'; |
46
|
|
|
|
47
|
|
|
if ($command->getDefinition()->hasOption('environment')) { |
48
|
|
|
$phinxArguments['--environment'] = 'default'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$phinxInput = new ArrayInput($phinxArguments); |
52
|
|
|
$command->run($phinxInput, $output); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|