仓库地址
Aquarmini/easyswoole-demogithub.com
试用 EasySwoole 自定义命令
创建文件
<?php
declare(strict_types=1);
namespace App\Command;
use EasySwoole\EasySwoole\Command\CommandInterface;
class DemoCommand implements CommandInterface
{
public function commandName(): string
{
return 'demo:command';
}
public function exec(array $args): ?string
{
var_dump('Hello World');
return 'success';
}
public function help(array $args): ?string
{
return 'help';
}
}
运行
$ php easyswoole
______ _____ _
| ____| / ____| | |
| |__ __ _ ___ _ _ | (___ __ __ ___ ___ | | ___
| __| / _` | / __| | | | | \___ \ \ \ /\ / / / _ \ / _ \ | | / _ \
| |____ | (_| | \__ \ | |_| | ____) | \ V V / | (_) | | (_) | | | | __/
|______| \__,_| |___/ \__, | |_____/ \_/\_/ \___/ \___/ |_| \___|
__/ |
|___/
Welcome To EASYSWOOLE Command Console!
Usage: php easyswoole [command] [arg]
Get help : php easyswoole help [command]
Current Register Command:
demo:command
help
install
start
stop
reload
phpunit
$ php easyswoole demo:command
string(11) "Hello World"
success
不得不说,还是相当简洁的。(我的学习交流群→)PHP高级交流677079770
改造
接下来,让我们开始改造一部分代码,给 EasySwoole 插上 Hyperf 的 Command。
EasySwoole 运行模式十分简单,所有的命令都保存在 CommandContainer
中,所以我们大可以修改入口文件,把