1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dbtlr\MigrationProvider\Provider; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration; |
6
|
|
|
use Doctrine\DBAL\Migrations\Tools\Console\Command; |
7
|
|
|
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; |
8
|
|
|
use Silex\ServiceProviderInterface; |
9
|
|
|
use Silex\Application; |
10
|
|
|
use Knp\Console\ConsoleEvents; |
11
|
|
|
use Knp\Console\ConsoleEvent; |
12
|
|
|
use Symfony\Component\Console\Helper\DialogHelper; |
13
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
14
|
|
|
|
15
|
|
|
class MigrationServiceProvider implements ServiceProviderInterface |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param Application $app |
19
|
|
|
*/ |
20
|
|
|
public function register(Application $app) |
21
|
|
|
{ |
22
|
|
|
$app['db.migrations.namespace'] = 'DoctrineMigrations'; |
23
|
|
|
$app['db.migrations.path'] = null; |
24
|
|
|
$app['db.migrations.table_name'] = null; |
25
|
|
|
$app['db.migrations.name'] = null; |
26
|
|
|
|
27
|
|
|
$app['dispatcher']->addListener(ConsoleEvents::INIT, function (ConsoleEvent $event) use ($app) { |
28
|
|
|
$application = $event->getApplication(); |
29
|
|
|
|
30
|
|
|
$helpers = array('dialog' => new DialogHelper()); |
|
|
|
|
31
|
|
|
|
32
|
|
|
if (isset($app['orm.em'])) { |
33
|
|
|
$helpers['em'] = new EntityManagerHelper($app['orm.em']); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$helperSet = new HelperSet($helpers); |
37
|
|
|
|
38
|
|
|
$application->setHelperSet($helperSet); |
39
|
|
|
|
40
|
|
|
$config = new Configuration($app['db']); |
41
|
|
|
$config->setMigrationsNamespace($app['db.migrations.namespace']); |
42
|
|
|
|
43
|
|
|
if ($app['db.migrations.path']) { |
44
|
|
|
$config->setMigrationsDirectory($app['db.migrations.path']); |
45
|
|
|
$config->registerMigrationsFromDirectory($app['db.migrations.path']); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($app['db.migrations.name']) { |
49
|
|
|
$config->setName($app['db.migrations.name']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($app['db.migrations.table_name']) { |
53
|
|
|
$config->setMigrationsTableName($app['db.migrations.table_name']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$commands = array( |
57
|
|
|
new Command\DiffCommand(), |
58
|
|
|
new Command\ExecuteCommand(), |
59
|
|
|
new Command\GenerateCommand(), |
60
|
|
|
new Command\MigrateCommand(), |
61
|
|
|
new Command\StatusCommand(), |
62
|
|
|
new Command\VersionCommand(), |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
foreach ($commands as $command) { |
66
|
|
|
/** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand $command */ |
67
|
|
|
$command->setMigrationConfiguration($config); |
68
|
|
|
$application->add($command); |
69
|
|
|
} |
70
|
|
|
}); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param Application $app |
75
|
|
|
*/ |
76
|
|
|
public function boot(Application $app) |
77
|
|
|
{ |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|