用 PHP imi 框架写自己的命令行脚本
Imi 官方文档【自己动手开发命令行工具】:https://doc.imiphp.com/v1/dev/tool.html
一、按照官方例子新建目录 Tool
,然后新建文件 Test.php
:
namespace ImiApp\Tool;
use Imi\Tool\Annotation\Tool;
use Imi\Tool\Annotation\Operation;
use Imi\Tool\Annotation\Arg;
/**
* @Tool("test")
*/
class Test
{
/**
* @Operation("hello")
* @Arg(name="username", type="string", default="默认值")
*/
public function hello($username)
{
echo "hello {$username}", PHP_EOL;
}
}
二、配置文件新增配置项
config/config.php
配置文件里,找到 beanScan
,新增数组项:
'ImiApp\Tool',
三、重启 imi 后,调用命令:
[root@localhost project-test]# vendor/bin/imi test/hello
hello 默认值
本文来自博客园,作者:imzhi,转载请注明原文链接:https://www.cnblogs.com/imzhi/p/php-imi-write-cli.html