首页›MVC 核心›CliController
CliController
Kuoqi\Core\CliController 是 CLI 命令基类(120 行):输入、路径、输出方法
本页内容
- 属性
- 构造行为
- 关键方法
属性
| 属性 | 说明 |
|---|---|
$__input | 命令剩余参数数组(input() 注入) |
$__helpers | 帮助文案数组(toHelper 输出) |
$__root_path / $__app_path / $__currect_path | 根/应用/当前目录 |
$__sub_path | 当前目录相对 Application 的路径 |
构造行为
构造函数:setConfig("HOME", getcwd());计算 root/app/currect 路径;从当前目录相对 Application 的路径推导 DEFAULT_MOD(第 2 段 code2hump)。
关键方法
| 方法 | 签名 | 说明 |
|---|---|---|
input | input($argv) | 注入命令参数 |
InitConfig | InitConfig($module="") | 加载模块 function.php 与 CliConfig.php |
start | start() | 无参数时输出帮助(子类覆写实现具体逻辑) |
toHelper | toHelper() | 输出 __helpers 帮助文案 |
write / writeLine | ($context, $colorCode=0) | 输出文本 / 单行文本 |
getCurrect | getCurrect($subPath="") | 当前目录拼接 |
console | console($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 ·
返回首页