title: Symfony2 console HelperSet
body: <p>i'm making application using Symfony2 components, and i got stuck with symfony console. The problem is that i initialize console</p>
  
  <pre><code>$objectRepository = ObjectRepository::getInstance();
  
  $console = $objectRepository-&gt;get('console');
  if ( ! $console instanceof \Symfony\Component\Console\Application) {
      echo 'Failed to initialize console.' . PHP_EOL;
  }
  
  $helperSet = $console-&gt;getHelperSet();
  $helperSet-&gt;set(new EntityManagerHelper($objectRepository-&gt;get('entity_manager')), 'em');
  
  $console-&gt;run();
  </code></pre>
  
  <p>And i have doctrine create command alias which is </p>
  
  <pre><code>namespace My\Console\Command;
  
  use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand as BaseCommand;
  
  class CreateCommand extends BaseCommand
  {
      protected function configure()
      {
          parent::configure();
  
          $this-&gt;setName('doctrine:schema:update');
      }
  
  }
  </code></pre>
  
  <p>Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand is using em helper, and the problem is in <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Application.php#L192" rel="nofollow">Symfony\Component\Console\Application doRun() method</a> </p>
  
  <pre><code>$command = $this-&gt;find($name);
  $this-&gt;runningCommand = $command;
  $statusCode = $command-&gt;run($input, $output);
  </code></pre>
  
  <p>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. </p>
  
  <p>I have solution to extend symfony default Application class and rewrite doRun() method, but that's not the best way.</p>