easyswoole 自定义命令

看了下官网的介绍,感觉和laravel 自定义命令差不多。

按照官方文档的例子代码如下:

namespace App\Command;

use EasySwoole\EasySwoole\Command\CommandInterface;
use EasySwoole\EasySwoole\Command\Utility;

class Show implements CommandInterface{

    public function commandName(): string
    {
        return "show";
    }

    public function exec(array $args): ?string
    {
        if(empty($args)){
           echo "参数为空!".PHP_EOL;
        }else{
            var_dump($args);
        }
        return null;
    }

    public function help(array $args): ?string
    {
        $logo = Utility::easySwooleLog();
        return $logo."this is test";
    }
}

官方说 新增/bootstrap.php文件添加注册文件,框架会自动注入,

但是 bootstrap是3.2.5新增的事件,它允许用户在框架初始化之前执行自定义事件 

我看了我的版本 刚好是 3.2.1 并没有这个功能,要么更新框架代码,要么去找源码,手动注入。

在入口文件看到单例模式的命令类 

$ret = CommandRunner::getInstance()->run($args);

在CommandRunner 类中注入自己写的测试类:

执行命令:php easyswoole show key 1111

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章