首页MVC 核心CliController
CliController
Kuoqi\Core\CliController 是 CLI 命令基类(120 行):输入、路径、输出方法
本页内容
  1. 属性
  2. 构造行为
  3. 关键方法

属性

属性说明
$__input命令剩余参数数组(input() 注入)
$__helpers帮助文案数组(toHelper 输出)
$__root_path / $__app_path / $__currect_path根/应用/当前目录
$__sub_path当前目录相对 Application 的路径

构造行为

构造函数:setConfig("HOME", getcwd());计算 root/app/currect 路径;从当前目录相对 Application 的路径推导 DEFAULT_MOD(第 2 段 code2hump)。

关键方法

方法签名说明
inputinput($argv)注入命令参数
InitConfigInitConfig($module="")加载模块 function.php 与 CliConfig.php
startstart()无参数时输出帮助(子类覆写实现具体逻辑)
toHelpertoHelper()输出 __helpers 帮助文案
write / writeLine($context, $colorCode=0)输出文本 / 单行文本
getCurrectgetCurrect($subPath="")当前目录拼接
consoleconsole($context)委托 app->console
自定义命令示例
namespace Kuoqi\Core\Cli\Demo;

class Create extends \Kuoqi\Core\CliController {
    protected $__helpers = array(
        "用法: demoCreate <名称>",
    );

    public function start() {
        if(count($this->__input) == 0){
            return $this->toHelper();
        }
        $name = array_shift($this->__input);
        $this->writeLine("创建: " . $name);
    }
}
KuoqiPHP v1.05 · 离线静态文档 · 界面基于 KuoqiUI · 返回首页