仓库地址
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 运行模式十分简单,所有的命令都保存在 C

本文介绍了如何将EasySwoole框架与HyperfCommand结合,通过创建自定义命令并改造EasySwoole的入口文件,实现对接。文章详细讲解了接管CommandInterface、创建HyperfCommand的过程,并展示了最终的执行效果。
最低0.47元/天 解锁文章
1891

被折叠的 条评论
为什么被折叠?



