处理CLI的路由
@return string|unknown
963182
private static function parseCLIRoute()
	{
		$mca = explode('/',Request::all(1,''));
		if(isset($mca[2]))
		{
			self::$module = ucfirst($mca[0]);
			self::$control = ucfirst($mca[1]);
			self::$action = $mca[2];
		}
		else if(isset($mca[1]))
		{
			self::$module = null;
			self::$control = ucfirst($mca[0]);
			self::$action = ucfirst($mca[1]);
		}
		else if(isset($mca[0]) && '' !== $mca[0])
		{
			self::$module = null;
			self::$control = null;
			self::$action = ucfirst($mca[0]);
		}
		else
		{
			self::$module = null;
			self::$control = null;
			self::$action = null;
		}
	}
707462
public function getOptionParser()
	{
		$parser = parent::getOptionParser();
		return $parser->description(
			'The Auditable shell.' .
			'')
			->addOption('connection', array(
					'short' => 'c',
					'default' => 'default',
					'help' => __d('Auditable', 'Set db config <config>. Uses \'default\' if none is specified.')))
			->addOption('force', array(
					'short' => 'f',
					'boolean' => true,
					'help' => __d('Auditable', 'Force changes in all tables of database.')))
			->addSubcommand('insert', array(
				'help' => __d('Auditable', 'Insert columns \'created_by\' and \'modified_by\' in all database tables.')))
			->addSubcommand('remove', array(
				'help' => __d('Auditable', 'Remove columns \'created_by\' and \'modified_by\' from all database tables.')));
	}
216221
public function getName()
    {
        $name = '';

        switch ($this->_clientId)
        {
            case Bootstrapper::SITE:
                $name = 'site';
                break;
            case Bootstrapper::ADMIN:
                $name = 'administrator';
                break;
            default:
                $name = 'cli';
                break;
        }

        return $name;
    }
1320252
private function cliIO()
    {
        $services = [
            'Cli\Input'  => 'input',
            'Cli\Output' => 'output',
        ];

        foreach ($services as $className => $classOffset) {
            $this->services->load($className, $classOffset);
        }
    }
173345
public function getCommand() : string
    {
        return $this->cmd
        . (count($this->options)   ? ' ' . implode(' ', $this->options)   : '')
        . ($this->isSilent         ? ' 2> /dev/null'                      : '');
    }
1053694
private function getCommand()
    {
        // Prefix command with exec on non Windows systems to ensure that we
        // receive the correct pid.
        // See http://php.net/manual/en/function.proc-get-status.php#93382
        $commandPrefix = $this->isWindows() ? '' : 'exec ';
        return $commandPrefix . escapeshellarg(realpath($this->config['path'])) . ' ' . $this->getCommandParameters();
    }
819131
public function getOptionParser() {
		$parser = parent::getOptionParser();
		$parser->description('There is no help');
		$taskNames = array_keys(Hash::normalize($this->tasks));
		foreach ($taskNames as $taskName) {
			$Task = $this->{$taskName};
			$parser->addSubcommand(Inflector::underscore($Task->name), array(
				'help' => $Task->getOptionParser()->description(),
				'parser' => $Task->getOptionParser()
			));
		}
		return $parser;
	}
898438
protected function _getCommand()
        {
            $command = $this->_bin;

            $command .= ($this->getCopies() > 1) ? " --copies " . $this->getCopies() : "";
            $command .= " --orientation " . $this->getOrientation();
            $command .= " --page-size " . $this->getPageSize();

            foreach($this->getMargins() as $position => $margin) {
                $command .= (false === is_null($margin)) ? sprintf(' --margin-%s %s', $position, $margin) : '';
            }

            $command .= ($this->getWindowStatus()) ? " --window-status ".$this->getWindowStatus()."" : "";
            $command .= ($this->getTOC()) ? " --toc" : "";
            $command .= ($this->getGrayscale()) ? " --grayscale" : "";
            $command .= (mb_strlen($this->getPassword()) > 0)
            ? " --password " . $this->getPassword() . ""
            : "";
            $command .= (mb_strlen($this->getUsername()) > 0)
            ? " --username " . $this->getUsername() . ""
            : "";
            $command .= (mb_strlen($this->getFooterHtml()) > 0)
            ? " --margin-bottom 20 --footer-html \"" . $this->getFooterHtml() . "\""
            : "";
            $command .= ($this->getTitle())
            ? ' --title "' . $this->getTitle() . '"'
            : '';

            $command .= ' "%input%"';
            $command .= " -";
            if ($this->getRunInVirtualX()) {
                $command = 'xvfb-run ' . $command;
            }
            return $command;
        }
1159158
public function compile()
    {
        $compiled = $this->command;

        // If callable, return the function itself
        if (is_callable($compiled)) {
            return $compiled;
        }

        // Augment with any supplied arguments
        foreach ($this->args as $key => $value) {
            $compiled .= ' ' . escapeshellarg($key);
            if ($value !== null) {
                $compiled .= ' ' . escapeshellarg($value);
            }
        }

        // Add the boilerplate to redirect the output to file/s
        if (count($this->outputTo) > 0) {
            $compiled .= ' | tee ';
            $compiled .= $this->outputMode === 'a' ? '-a ' : '';
            foreach ($this->outputTo as $file) {
                $compiled .= $file . ' ';
            }

            $compiled = trim($compiled);
        }

        // Add boilerplate to remove lockfile after execution
        if ($this->lockFile) {
            $compiled .= '; rm ' . $this->lockFile;
        }

        // Add boilerplate to run in background
        if ($this->canRunInBackground()) {
            // Parentheses are need execute the chain of commands in a subshell
            // that can then run in background
            $compiled = '(' . $compiled . ') > /dev/null 2>&1 &';
        }

        return trim($compiled);
    }
624924
public function completeCommand()
    {
        $arguments = array_slice($GLOBALS['argv'], 3);
        $position = (int)$arguments[0];

        $arguments = array_slice($arguments, 1);

        $count = count($arguments);

        $controller = null;
        if ($count > 1) {
            $controller = $arguments[1];
        }

        $command = null;
        if ($count > 2) {
            $command = $arguments[2];
            if ($command !== '' && $command[0] === '-') {
                $command = 'default';
            }
        }

        $previous = $position > 0 ? $arguments[$position - 1] : null;

        $current = isset($arguments[$position]) ? $arguments[$position] : '';

        if ($position === 1) {
            $words = $this->_getControllers();
        } elseif ($current !== '' && $current[0] === '-') {
            $words = $this->_getArgumentNames($controller, $command);
        } elseif ($position === 2) {
            $words = $this->_getCommands($controller);
        } else {
            $words = $this->_getArgumentValues($controller, $command, $previous);
        }

        $this->console->writeLn(implode(' ', $this->_filterWords($words, $current)));

        return 0;
    }
510821
public static function parseCommand()
    {
        // 检查运行命令的参数
        global $argv;
        $startFile = $argv[0];
        if ( ! isset($argv[1]))
        {
            self::printUsage($startFile);
            exit;
        }

        // 命令
        $command = trim($argv[1]);

        // 子命令，目前只支持-d
        $command2 = isset($argv[2]) ? $argv[2] : '';

        // 记录日志
        $mode = '';
        if ($command === 'start')
        {
            if ($command2 === '-d')
            {
                $mode = 'in DAEMON mode';
            }
            else
            {
                $mode = 'in DEBUG mode';
            }
        }

        Base::getLog()->debug(__METHOD__ . ' parse and execute command', [
            'file'    => $startFile,
            'command' => $command,
            'mode'    => $mode,
        ]);

        // 检查主进程是否在运行
        $masterPid = @file_get_contents(self::$pidFile);
        Base::getLog()->debug(__METHOD__ . ' get master pid from pidFile', [
            'file' => self::$pidFile,
            'pid'  => $masterPid,
        ]);

        $masterIsAlive = $masterPid && @posix_kill($masterPid, 0);
        Base::getLog()->debug(__METHOD__ . ' if master is alive', [
            'alive' => $masterIsAlive,
        ]);

        if ($masterIsAlive)
        {
            if ($command === 'start')
            {
                Base::getLog()->debug(__METHOD__ . ' server is running', [
                    'file' => $startFile,
                ]);
            }
        }
        elseif ($command !== 'start' && $command !== 'restart')
        {
            Base::getLog()->debug(__METHOD__ . ' server is not running', [
                'file' => $startFile,
            ]);
        }

        // 根据命令做相应处理
        switch ($command)
        {
            // 启动 workerman
            case 'start':
                if ($command2 === '-d')
                {
                    Worker::$daemonize = true;
                }
                break;
            // 显示 workerman 运行状态
            case 'status':
                // 尝试删除统计文件，避免脏数据
                if (is_file(self::$statusFile))
                {
                    Base::getLog()->debug(__METHOD__ . ' delete old status file', [
                        'file' => self::$statusFile,
                    ]);
                    @unlink(self::$statusFile);
                }
                // 向主进程发送 SIGUSR2 信号 ，然后主进程会向所有子进程发送 SIGUSR2 信号
                // 所有进程收到 SIGUSR2 信号后会向 $statusFile 写入自己的状态
                posix_kill($masterPid, SIGUSR2);
                // 睡眠100毫秒，等待子进程将自己的状态写入 $statusFile 指定的文件
                usleep(100000);
                // 展示状态
                if ( ! is_file(self::$statusFile))
                {
                    exit("Status file is missing.\n");
                }
                readfile(self::$statusFile);
                exit(0);
            // 重启 workerman
            case 'restart':
                // 停止 workeran

            case 'stop':

                Base::getLog()->debug(__METHOD__ . ' stopping all services', [
                    'file' => $startFile,
                ]);

                // 想主进程发送SIGINT信号，主进程会向所有子进程发送SIGINT信号
                $masterPid && posix_kill($masterPid, SIGINT);
                // 如果 $timeout 秒后主进程没有退出则展示失败界面
                $timeout = 5;
                $startTime = time();
                while (1)
                {
                    // 检查主进程是否存活
                    $masterIsAlive = $masterPid && posix_kill($masterPid, 0);
                    if ($masterIsAlive)
                    {
                        // 检查是否超过$timeout时间
                        if (time() - $startTime >= $timeout)
                        {
                            self::log("Workerman[$startFile] stop fail");
                            exit;
                        }
                        usleep(10000);
                        continue;
                    }
                    self::log("Workerman[$startFile] stop success");
                    // 是restart命令
                    if ($command === 'stop')
                    {
                        exit(0);
                    }
                    // -d 说明是以守护进程的方式启动
                    if ($command2 === '-d')
                    {
                        Worker::$daemonize = true;
                    }
                    break;
                }
                break;
            // 平滑重启 workerman
            case 'reload':
                posix_kill($masterPid, SIGUSR1);
                self::log("Workerman[$startFile] reload");
                exit;
            // 未知命令
            default :
                self::printUsage($startFile);
                exit;
        }
    }
156654
public function getCmdString()
    {
        // Add no-debug arg if it isn't already present
        if (!$this->debug && !$this->isNoDebugArgPresent()) {
            $this->createArg()->setName("no-debug");
        }
        $cmd = [
            Commandline::quoteArgument($this->console),
            $this->command,
            implode(' ', $this->args)
        ];
        $cmd = implode(' ', $cmd);

        return $cmd;
    }
1332617
protected function getDefaultCommands() {
        $defaultCommands = [];
        /*
        foreach (self::$defaultCommands as $classname) {
            if (class_exists($classname) && is_subclass_of($classname, "nb\\console\\Driver")) {
                $defaultCommands[] = new $classname();
            }
        }
        */
        //更换为接口
        //self::$defaultCommands
        foreach ($this->defaultCommands as $classname) {
            if (class_exists($classname) && is_subclass_of($classname, "nb\\console\\Command")) {

                $defaultCommands[] = new Pack(new $classname());
            }
        }

        return $defaultCommands;
    }
104660
public function getOmmuScript() 
	{
		$module = strtolower(Yii::app()->controller->module->id);
		$controller = strtolower(Yii::app()->controller->id);
		$action = strtolower(Yii::app()->controller->action->id);
		if(isset($_GET))
			$attr = array_merge($_GET, array('protocol'=>'script'));
		else
			$attr = array('protocol'=>'script');
		
		if($module == 'null')
			$url = Yii::app()->createUrl($controller.'/'.$action, $attr);
		else
			$url = Yii::app()->createUrl($module.'/'.$controller.'/'.$action, $attr);
		
		$return = array();
		$return['cssFiles'] = $this->getCssFiles();
		$return['scriptFiles'] = $this->getScriptFiles();
		$return['scriptFiles'][] = $url;
		//$return['scripts'] = $this->getScripts();
		$return['powered'] = 'Ommu Platform by putra@sudaryanto.id';
		
		return $return;
	}
1112357
private function getCLICommandArguments()
    {
        $command = '';
        $combinedArguments = array_merge($this->globalCommandArguments, $this->commandArguments);
        if (count($combinedArguments) > 0) {
            $command .= ' ' . implode(' ', array_map('escapeshellarg', $combinedArguments));
        }
        return $command;
    }
791047
public function getOptionParser()
    {
        $parser = parent::getOptionParser();

        $parser->addOption('cli', [
                'help' => 'Use the bootstrap_cli file.',
                'boolean' => true,
                'default' => false,
            ])
            ->addOption('no_app', [
                'help' => 'Do not update the Application if it exist. Forces config/bootstrap.php to be updated.',
                'boolean' => true,
                'default' => false,
            ])
            ->addArgument('plugin', [
                'help' => 'Name of the plugin to load.',
            ]);

        return $parser;
    }
880579
private function getProcessCommand()
    {
        $options   = $this->transformOptions();
        $options[] = escapeshellarg($this->input);

        $command = $this->binary . ' ' . implode(' ', $options);

        return $command;
    }