-
-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have to specifiy file/database connection while I already have #780
Comments
How are you then setting the $helperset? |
@jwage Then after, the commands get added to |
Ok I will try to reproduce it. |
The expected name of the helper is
|
and that was already the case in 1.x |
Interesting, I am not sure how it worked before then. |
I don't see a string |
Yeah, i noticed the same what @stof said but I was so confused, so hence this issue, I based it all on the docs. I downgraded back to 1.x before and checked for the same helper name but on previous versions it's also I've tried to debug and follow the flow but i can't find anything yet. I'll try tomorrow with the name |
I am suspecting that maybe previously if Is it possible to share a more complete example of your setup? or preferably a test in the 2.0 branch? I suspect there might be something else going on that I can't see from your example. |
So our use case is that we have a file We put them in an array and loop through them. We do that because we need to overwrite their code (with And depending on those options we create the right entitymanager/database connection, following by the helperset and then set the helperset to the console application. Afterwards we add the command to the console application and run it. $consoleApp = new Application();
$consoleApp->getDefinition()->addOptions([
new InputOption('app', null, InputOption::VALUE_OPTIONAL, 'The app.', 'default'),
]);
$consoleApp->getDefinition()->addOption(
new InputOption('env', null, InputOption::VALUE_OPTIONAL, 'The environment to operate in.', $app->environment())
);
$consoleApp->getDefinition()->addOption(
new InputOption('config', null, InputOption::VALUE_OPTIONAL, 'The application environment.', $app->client())
);
$databaseAwareCommands = [
//...
\Doctrine\Migrations\Tools\Console\Command\DiffCommand::class,
\Doctrine\Migrations\Tools\Console\Command\ExecuteCommand::class,
\Doctrine\Migrations\Tools\Console\Command\GenerateCommand::class,
\Doctrine\Migrations\Tools\Console\Command\LatestCommand::class,
\Doctrine\Migrations\Tools\Console\Command\MigrateCommand::class,
\Doctrine\Migrations\Tools\Console\Command\StatusCommand::class,
\Doctrine\Migrations\Tools\Console\Command\UpToDateCommand::class,
\Doctrine\Migrations\Tools\Console\Command\VersionCommand::class,
//...
];
foreach ($databaseAwareCommands as $command) {
/** @var \Symfony\Component\Console\Command\Command $c */
$c = new $command();
$c->setCode(function (InputInterface $input, OutputInterface $output) use ($consoleApp, $app, $command) {
//...
$entityManager = AthenaManager::get(); //returns new EntityManager based on the options
$helperset = new HelperSet([
'dialog' => new QuestionHelper(),
'db' => new ConnectionHelper($entityManager->getConnection()),
'em' => new EntityManagerHelper($entityManager)
]);
$consoleApp->setHelperSet($helperset);
$com = $consoleApp->add(new $command());
try {
$com->run($input, $output);
} catch (Exception $exception) {
$io = new SymfonyStyle($input, $output);
$io->error($exception->getMessage());
}
});
$consoleApp->add($c);
}
$consoleApp->run(); The annoying thing is also I'm not able to debug the anonymous function of |
I've tracked the debugger and concluded in version 1.8 it gets the connection via EDIT: so in the constructor of So ok i think i got it @jwage : So the point is I probably need to find a different approach to be able to support multiple databases, or issue #503 |
or you could add the helper as |
That doesn't work because it will still call
|
hmm indeed. The callable passed to Your logic instantiating a command and replacing its execution code will indeed never work as soon as the command relies on other extension points of the Symfony Console component. That's not an expected usage. I would say you are on your own here. |
Well, yeah I've fixed it by using symfony events for now. The same way someone else handled this: #503 (comment) //....
$consoleApp->addCommands(array_map(function($cmd) { return new $cmd(); }, $databaseAwareCommands));
$eventDispatcher = new EventDispatcher();
$eventDispatcher->addListener(ConsoleEvents::COMMAND,
function (ConsoleCommandEvent $consoleCommandEvent) use ($app) {
//...
$entityManager = AthenaManager::get();
$helperset = new HelperSet([
'dialog' => new QuestionHelper(),
'db' => new ConnectionHelper($entityManager->getConnection()),
'em' => new EntityManagerHelper($entityManager)
]);
$consoleCommandEvent->getCommand()->setHelperSet($helperset);
$output->writeln("Executing in environment '{$input->getOption('env')}' with config '{$input->getOption('config')}' in app '{$input->getOption('app')}'");
}
);
$consoleApp->setDispatcher($eventDispatcher);
$consoleApp->run(); I guess this issue can be closed? I'll let u guys decide |
In 3.x that is possilbe using the |
Bug Report
Summary
Not sure if i'm missing something but after upgrading to 2.0.0 and executing - for example the status command - the output is
I followed the upgrade log but any changes about the Helperset or configuration aren't mentioned. So I'm not sure what's going on.
This is my helperset
which then gets set to the console application of symfony.
Current behavior
Executing a migration command results in an error about the helperset of symfony? While it did not before.
How to reproduce
All I did was:
migrations:status
The text was updated successfully, but these errors were encountered: