/**
  * Initializes default command definitions
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected final function initialize(InputInterface $input, OutputInterface $output)
 {
     // Set container and application.
     $this->application = parent::getApplication();
     $this->container = $this->application->getContainer();
     // Dispatch pre execute event.
     $dispatcher = $this->container->getServiceBag()->getDispatcher();
     $dispatcher->dispatch(Events::PRE_INITIALIZE, new PreInitializeEvent($this->container));
     // Initialize child class.
     $this->initializeCommand($input, $output);
     // Dispatch post execute event.
     $dispatcher->dispatch(Events::POST_INITIALIZE, new PostInitializeEvent($this->container));
 }
 /**
  * @inheritdoc
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     // Define the running environment and initialize the container.
     $env = $input->getParameterOption(array('-e', '--env'), 'dev');
     $this->container->getApplicationBag()->setEnv($env);
     $this->container->getConsoleBag()->set('input', $input)->set('output', $output);
     $this->container->initialize();
     // Add commands.
     foreach ($this->container->getCommandBag()->values() as $command) {
         $this->add($command);
     }
     // Dispatch pre run event.
     $dispatcher = $this->container->getServiceBag()->getDispatcher();
     $dispatcher->dispatch(Events::PRE_RUN, new PreRunEvent($this->container));
     // Run application.
     $result = parent::doRun($input, $output);
     // Dispatch post run event.
     $dispatcher->dispatch(Events::POST_RUN, new PostRunEvent($this->container, $result));
     return $result;
 }