1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations\Tools\Console; |
6
|
|
|
|
7
|
|
|
use Doctrine\Migrations\MigrationsVersion; |
8
|
|
|
use Doctrine\Migrations\Tools\Console\Command\AbstractCommand; |
9
|
|
|
use Doctrine\Migrations\Tools\Console\Command\DiffCommand; |
10
|
|
|
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand; |
11
|
|
|
use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; |
12
|
|
|
use Doctrine\Migrations\Tools\Console\Command\LatestCommand; |
13
|
|
|
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand; |
14
|
|
|
use Doctrine\Migrations\Tools\Console\Command\StatusCommand; |
15
|
|
|
use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand; |
16
|
|
|
use Doctrine\Migrations\Tools\Console\Command\VersionCommand; |
17
|
|
|
use Symfony\Component\Console\Application; |
18
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
19
|
|
|
|
20
|
|
|
class ConsoleRunner |
21
|
|
|
{ |
22
|
|
|
/** @param AbstractCommand[] $commands */ |
23
|
|
|
public static function run(HelperSet $helperSet, array $commands = []) : void |
24
|
|
|
{ |
25
|
|
|
$cli = self::createApplication($helperSet, $commands); |
26
|
|
|
$cli->run(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** @param AbstractCommand[] $commands */ |
30
|
1 |
|
public static function createApplication(HelperSet $helperSet, array $commands = []) : Application |
31
|
|
|
{ |
32
|
1 |
|
$cli = new Application('Doctrine Migrations', MigrationsVersion::VERSION()); |
33
|
1 |
|
$cli->setCatchExceptions(true); |
34
|
1 |
|
$cli->setHelperSet($helperSet); |
35
|
1 |
|
self::addCommands($cli); |
36
|
1 |
|
$cli->addCommands($commands); |
37
|
|
|
|
38
|
1 |
|
return $cli; |
39
|
|
|
} |
40
|
|
|
|
41
|
10 |
|
public static function addCommands(Application $cli) : void |
42
|
|
|
{ |
43
|
10 |
|
$cli->addCommands([ |
44
|
10 |
|
new ExecuteCommand(), |
45
|
10 |
|
new GenerateCommand(), |
46
|
10 |
|
new LatestCommand(), |
47
|
10 |
|
new MigrateCommand(), |
48
|
10 |
|
new StatusCommand(), |
49
|
10 |
|
new VersionCommand(), |
50
|
10 |
|
new UpToDateCommand(), |
51
|
|
|
]); |
52
|
|
|
|
53
|
10 |
|
if (! $cli->getHelperSet()->has('em')) { |
54
|
9 |
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
$cli->add(new DiffCommand()); |
58
|
1 |
|
} |
59
|
|
|
} |
60
|
|
|
|