自定义命令

最后更新于:2022-04-02 02:21:15

[TOC] 新建文件 `App/Command/Test.php` ``` namespace App\Command; use EasySwoole\EasySwoole\Command\CommandInterface; use EasySwoole\EasySwoole\Command\Utility; class Test implements CommandInterface { public function commandName(): string { return 'test'; } public function exec(array $args): ?string { //打印参数,打印测试值 var_dump($args); echo 'test'.PHP_EOL; return null; } public function help(array $args): ?string { //输出logo $logo = Utility::easySwooleLog(); return $logo."this is test"; } } ``` ## 新建 `/bootstrap.php` ``` \EasySwoole\EasySwoole\Command\CommandContainer::getInstance()->set(new \App\Command\Test()); ``` > bootstrap是3.2.5新增的事件,它允许用户在框架初始化之前执行自定义事件 ``` php easyswoole test php easyswoole test 123 123 php easyswoole help test ```
';