i'm making application using Symfony2 components, and i got stuck with symfony console. The problem is that i initialize console
$objectRepository = ObjectRepository::getInstance();
$console = $objectRepository->get('console');
if ( ! $console instanceof \Symfony\Component\Console\Application) {
echo 'Failed to initialize console.' . PHP_EOL;
}
$helperSet = $console->getHelperSet();
$helperSet->set(new EntityManagerHelper($objectRepository->get('entity_manager')), 'em');
$console->run();
And i have doctrine create command alias which is
namespace My\Console\Command;
use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand as BaseCommand;
class CreateCommand extends BaseCommand
{
protected function configure()
{
parent::configure();
$this->setName('doctrine:schema:update');
}
}
Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand is using em helper, and the problem is in Symfony\Component\Console\Application doRun() method
$command = $this->find($name);
$this->runningCommand = $command;
$statusCode = $command->run($input, $output);
Application keeps 3 helpers in HelperSet which are (dialog, format, entityManager and em (em is an alias for entityManager)). After command is found, command does not inherit Application helper set and has only default dialog and format helpers.
I have solution to extend symfony default Application class and rewrite doRun() method, but that's not the best way.