run(); } /** @param DoctrineCommand[] $commands */ public static function createApplication(array $commands = [], ?DependencyFactory $dependencyFactory = null): Application { $cli = new Application('Doctrine Migrations', Versions::getVersion('doctrine/migrations')); $cli->setCatchExceptions(true); self::addCommands($cli, $dependencyFactory); $cli->addCommands($commands); return $cli; } public static function addCommands(Application $cli, ?DependencyFactory $dependencyFactory = null): void { $cli->addCommands([ new CurrentCommand($dependencyFactory), new DumpSchemaCommand($dependencyFactory), new ExecuteCommand($dependencyFactory), new GenerateCommand($dependencyFactory), new LatestCommand($dependencyFactory), new MigrateCommand($dependencyFactory), new RollupCommand($dependencyFactory), new StatusCommand($dependencyFactory), new VersionCommand($dependencyFactory), new UpToDateCommand($dependencyFactory), new SyncMetadataCommand($dependencyFactory), new ListCommand($dependencyFactory), ]); if ($dependencyFactory === null || ! $dependencyFactory->hasSchemaProvider()) { return; } $cli->add(new DiffCommand($dependencyFactory)); } /** * @param mixed|HelperSet $dependencyFactory * * @return mixed|DependencyFactory */ private static function checkLegacyConfiguration($dependencyFactory, string $configurationFile) { if (! ($dependencyFactory instanceof HelperSet)) { return $dependencyFactory; } $configurations = new ConfigurationFileWithFallback(); if ($dependencyFactory->has('em') && $dependencyFactory->get('em') instanceof EntityManagerHelper) { return DependencyFactory::fromEntityManager( $configurations, new ExistingEntityManager($dependencyFactory->get('em')->getEntityManager()) ); } if ($dependencyFactory->has('db') && $dependencyFactory->get('db') instanceof ConnectionHelper) { return DependencyFactory::fromConnection( $configurations, new ExistingConnection($dependencyFactory->get('db')->getConnection()) ); } throw new RuntimeException(sprintf( 'Configuration HelperSet returned by "%s" does not have a valid "em" or the "db" helper.', $configurationFile )); } }