看了下官網的介紹,感覺和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