学习路之TP6 --重写vendor目录下的文件(新建命令)
@[TOC](学习路之TP6 --重写vendor目录下的文件(新建命令))
一、新建命令文件
php think make:command CustomWorker
二、修改
复制vendor\topthink\think-worker\src\command\Server.php 内容到app\command\CustomWorker.php
修改继承类:class CustomWorker extends \think\worker\command\Server
重写要更改的方法:这里是execute这个方法,具体看个人需求
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\App;
use think\facade\Config;
use think\worker\Server as WorkerServer;
use Workerman\Worker;
/**
* Worker Server 命令行类
*/
class CustomWorker extends \think\worker\command\Server
{
public function execute(Input $input, Output $output)
{
$action = $input->getArgument('action');
$output->writeln('Starting Workerman server...CustomWorkerCustomWorkerCustomWorkerCustomWorker');
return ;
}
}
三、运行效果
php think custom-server