1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Ecodev\Felix\Console; |
6
|
|
|
|
7
|
|
|
use Composer\InstalledVersions; |
8
|
|
|
use Doctrine\Migrations\DependencyFactory; |
9
|
|
|
use Doctrine\Migrations\Tools\Console\Command\CurrentCommand; |
10
|
|
|
use Doctrine\Migrations\Tools\Console\Command\DiffCommand; |
11
|
|
|
use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand; |
12
|
|
|
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand; |
13
|
|
|
use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; |
14
|
|
|
use Doctrine\Migrations\Tools\Console\Command\LatestCommand; |
15
|
|
|
use Doctrine\Migrations\Tools\Console\Command\ListCommand; |
16
|
|
|
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand; |
17
|
|
|
use Doctrine\Migrations\Tools\Console\Command\RollupCommand; |
18
|
|
|
use Doctrine\Migrations\Tools\Console\Command\StatusCommand; |
19
|
|
|
use Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand; |
20
|
|
|
use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand; |
21
|
|
|
use Doctrine\Migrations\Tools\Console\Command\VersionCommand; |
22
|
|
|
use Doctrine\ORM\EntityManager; |
23
|
|
|
use Doctrine\ORM\Tools\Console\ConsoleRunner; |
24
|
|
|
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider; |
25
|
|
|
use Ecodev\Felix\DBAL\EventListener\HideMigrationStorage; |
26
|
|
|
use Laminas\ServiceManager\Factory\FactoryInterface; |
27
|
|
|
use Psr\Container\ContainerInterface; |
28
|
|
|
use Symfony\Component\Console\Application; |
29
|
|
|
|
30
|
|
|
final class ApplicationFactory implements FactoryInterface |
31
|
|
|
{ |
32
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): Application |
33
|
|
|
{ |
34
|
|
|
/** @var DependencyFactory $dependencyFactory */ |
35
|
|
|
$dependencyFactory = $container->get(DependencyFactory::class); |
36
|
|
|
|
37
|
|
|
/** @var HideMigrationStorage $dispatcher */ |
38
|
|
|
$dispatcher = $container->get(HideMigrationStorage::class); |
39
|
|
|
|
40
|
|
|
/** @var EntityManager $entityManager */ |
41
|
|
|
$entityManager = $container->get(EntityManager::class); |
42
|
|
|
$entityManagerProvider = new SingleManagerProvider($entityManager); |
43
|
|
|
|
44
|
|
|
$commands = [ |
45
|
|
|
new CurrentCommand($dependencyFactory), |
46
|
|
|
new DumpSchemaCommand($dependencyFactory), |
47
|
|
|
new ExecuteCommand($dependencyFactory), |
48
|
|
|
new GenerateCommand($dependencyFactory), |
49
|
|
|
new LatestCommand($dependencyFactory), |
50
|
|
|
new MigrateCommand($dependencyFactory), |
51
|
|
|
new RollupCommand($dependencyFactory), |
52
|
|
|
new StatusCommand($dependencyFactory), |
53
|
|
|
new VersionCommand($dependencyFactory), |
54
|
|
|
new UpToDateCommand($dependencyFactory), |
55
|
|
|
new SyncMetadataCommand($dependencyFactory), |
56
|
|
|
new ListCommand($dependencyFactory), |
57
|
|
|
new DiffCommand($dependencyFactory), |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
$version = InstalledVersions::getVersion('ecodev/felix'); |
61
|
|
|
assert($version !== null); |
62
|
|
|
|
63
|
|
|
$cli = new Application('Felix', $version); |
64
|
|
|
$cli->setDispatcher($dispatcher); |
65
|
|
|
$cli->setCatchExceptions(true); |
66
|
|
|
|
67
|
|
|
ConsoleRunner::addCommands($cli, $entityManagerProvider); |
68
|
|
|
$cli->addCommands($commands); |
69
|
|
|
|
70
|
|
|
return $cli; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|