/**
  * {@inheritDoc}
  * @see CConsoleCommandRunner::createCommand()
  */
 public function createCommand($name)
 {
     if (strpos($name, '/') !== false) {
         // route. Search if the route is valid, otherwise is a path, and
         // should not be modified.
         $route_parts = explode('/', trim($name, '/'));
         $module_parts = array_slice($route_parts, 0, -1);
         // a route is composed of module/submodule1/submodule2/.../class
         $commandpath = implode('/', $module_parts);
         if (!in_array($commandpath, $this->_modules_searched)) {
             $module = YiiPlug::app();
             foreach ($module_parts as $module_route) {
                 if ($module !== null) {
                     $module = $module->getModule($module_route);
                 } else {
                     break;
                 }
             }
             if ($module !== null) {
                 /* @var $module CModule */
                 $modulepath = $module->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
                 $commands = $this->findCommands($modulepath);
                 foreach ($commands as $cname => $command) {
                     $this->commands[$commandpath . '/' . $cname] = $command;
                 }
             }
             $this->_modules_searched[] = $commandpath;
         }
     }
     return parent::createCommand($name);
 }
Esempio n. 2
0
 protected function runShell()
 {
     // disable E_NOTICE so that the shell is more friendly
     error_reporting(E_ALL ^ E_NOTICE);
     $_runner_ = new CConsoleCommandRunner();
     $_runner_->addCommands(dirname(__FILE__) . '/shell');
     $_runner_->addCommands(Yii::getPathOfAlias('application.commands.shell'));
     if (($_path_ = @getenv('YIIC_SHELL_COMMAND_PATH')) !== false) {
         $_runner_->addCommands($_path_);
     }
     $_commands_ = $_runner_->commands;
     $log = Yii::app()->log;
     while (($_line_ = $this->prompt("\n>>")) !== false) {
         $_line_ = trim($_line_);
         if ($_line_ === 'exit') {
             return;
         }
         try {
             $_args_ = preg_split('/[\\s,]+/', rtrim($_line_, ';'), -1, PREG_SPLIT_NO_EMPTY);
             if (isset($_args_[0]) && isset($_commands_[$_args_[0]])) {
                 $_command_ = $_runner_->createCommand($_args_[0]);
                 array_shift($_args_);
                 $_command_->init();
                 $_command_->run($_args_);
             } else {
                 echo eval($_line_ . ';');
             }
         } catch (Exception $e) {
             if ($e instanceof ShellException) {
                 echo $e->getMessage();
             } else {
                 echo $e;
             }
         }
     }
 }