我一直在尝试使用我自己的 Doctrine \ Dbal \ Connection 对象与Doctrine Migrations,这是我到目前为止所得到的,但它一直告诉我提供 - db -configuration 文件,这不是我想要的。
// CLI script for Doctrine Migrations
$app = require 'bootstrap.php';
$cli = new Symfony\Component\Console\Application('Doctrine CLI');
$cli->addCommands([
new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
]);
$helperSet = new Symfony\Component\Console\Helper\HelperSet([
// Doctrine\DBAL\Connection $app->getContainer()->db
'connection' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($app->getContainer()->db),
'dialog' => new \Symfony\Component\Console\Helper\QuestionHelper(),
]);
$cli->setHelperSet($helperSet);
$cli->run();
例外:
[InvalidArgumentException]
You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrat
ions.
答案 0 :(得分:0)
es5
需要先于
$cli->setHelperSet($helperSet);
以便将helperSet传递给每个命令。
资料来源:我也为此付出了很多努力,直到我意识到自己的错误(与您的错误相同,并且可能是这个问题的未来访问者)之前,都仔细研究了代码以了解其工作原理。