/**
  * Create a controller
  *
  * @return ConsoleModel
  */
 public function controllerAction()
 {
     // check for help mode
     if ($this->requestOptions->getFlagHelp()) {
         return $this->controllerHelp();
     }
     // output header
     $this->consoleHeader('Creating new controller');
     // get needed options to shorten code
     $path = $this->requestOptions->getPath();
     $flagWithFactory = $this->requestOptions->getFlagWithFactory();
     $moduleName = $this->requestOptions->getModuleName();
     $modulePath = $this->requestOptions->getModulePath();
     $controllerName = $this->requestOptions->getControllerName();
     $controllerPath = $this->requestOptions->getControllerPath();
     $controllerClass = $this->requestOptions->getControllerClass();
     $controllerFile = $this->requestOptions->getControllerFile();
     $controllerViewPath = $this->requestOptions->getControllerViewPath();
     $actionViewFile = $this->requestOptions->getActionViewFile();
     // check for module path and application config
     if (!file_exists($path . '/module') || !file_exists($path . '/config/application.config.php')) {
         return $this->sendError(array(array(Color::NORMAL => 'The path '), array(Color::RED => $path), array(Color::NORMAL => ' doesn\'t contain a ZF2 application.')));
     }
     // check if controller name provided
     if (!$controllerName) {
         return $this->sendError(array(array(Color::NORMAL => 'Please provide the controller name as parameter.')));
     }
     // check if module name provided
     if (!$moduleName) {
         return $this->sendError(array(array(Color::NORMAL => 'Please provide the module name as parameter.')));
     }
     // set mode
     if (file_exists($controllerPath . $controllerFile)) {
         $mode = 'update';
     } else {
         $mode = 'insert';
     }
     // check if controller exists already in module
     if ($mode == 'update' && !$flagWithFactory) {
         return $this->sendError(array(array(Color::NORMAL => 'The controller '), array(Color::RED => $controllerName), array(Color::NORMAL => ' already exists in module '), array(Color::RED => $moduleName), array(Color::NORMAL => '.')));
     }
     if ($mode == 'insert') {
         // write start message
         $this->console->write('       => Creating controller ');
         $this->console->write($controllerName, Color::GREEN);
         $this->console->write(' in module ');
         $this->console->writeLine($moduleName, Color::GREEN);
         // create controller class
         $controllerFlag = $this->moduleGenerator->createController();
         // write start message
         $this->console->write('       => Creating view script ');
         $this->console->write($actionViewFile, Color::GREEN);
         $this->console->write(' in ');
         $this->console->writeLine($controllerViewPath, Color::GREEN);
         // create view script
         $viewScriptFlag = $this->moduleGenerator->createViewScript();
         // write start message
         $this->console->write('       => Adding controller configuration for ');
         $this->console->writeLine($moduleName, Color::GREEN);
         // add controller configuration to module
         $moduleConfig = $this->moduleConfigurator->addControllerConfig();
     }
     // check for factory flag
     if ($flagWithFactory) {
         // create controller factory class
         try {
             $factoryFlag = $this->moduleGenerator->createControllerFactory();
         } catch (GeneratorException $e) {
             return $this->sendError(array(array(Color::NORMAL => 'The factory for the controller '), array(Color::RED => $controllerName), array(Color::NORMAL => ' of module '), array(Color::RED => $moduleName), array(Color::NORMAL => ' exists already.')));
         }
         // write start message
         $this->console->write('       => Creating factory for controller ');
         $this->console->write($controllerName, Color::GREEN);
         $this->console->write(' in module ');
         $this->console->writeLine($moduleName, Color::GREEN);
         // add controller factory configuration to module
         $moduleConfig = $this->moduleConfigurator->addControllerFactoryConfig();
     } else {
         $factoryFlag = false;
     }
     // check for module config updates
     if ($moduleConfig) {
         // update module configuration
         $this->moduleGenerator->updateConfiguration($moduleConfig, $modulePath . '/config/module.config.php');
         // write start message
         $this->console->write('       => Updating configuration for module ');
         $this->console->writeLine($moduleName, Color::GREEN);
     }
     $this->console->writeLine();
     $this->console->write(' Done ', Color::NORMAL, Color::CYAN);
     $this->console->write(' ');
     // write message
     if ($factoryFlag) {
         $this->console->write('The controller ');
         $this->console->write($controllerName, Color::GREEN);
         $this->console->write(' has been created with a factory in module ');
         $this->console->writeLine($moduleName, Color::GREEN);
     } else {
         $this->console->write('The controller ');
         $this->console->write($controllerName, Color::GREEN);
         $this->console->write(' has been created in module ');
         $this->console->writeLine($moduleName, Color::GREEN);
     }
     // output footer
     $this->consoleFooter('controller was successfully created');
 }