学习路之TP6 --重写vendor目录下的文件(新建命令)

@TOC(学习路之TP6 --重写vendor目录下的文件(新建命令))

一、新建命令文件

bash 复制代码
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这个方法,具体看个人需求

bash 复制代码
<?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

相关推荐
β添砖java2 小时前
2025最新快速构建企业级虚拟专用网络环境学习笔记
笔记·学习
WZF-Sang6 小时前
网络基础——2
服务器·网络·c++·学习·网络编程·php
心中有国也有家7 小时前
E-Brufen 技术选型全景:Flutter + 鸿蒙 + Hive CE
hive·hadoop·学习·flutter·华为·harmonyos
New农民工8 小时前
射频芯片学习-ExpressLRS 对频流程分析
学习
Tom@敲代码8 小时前
js学习笔记-01
javascript·笔记·学习
辞旧 lekkk9 小时前
【Qt】 系统相关:事件与定时器
开发语言·qt·学习·萌新
zzzll11119 小时前
如何学习AI Agent?
java·人工智能·学习·程序员·大模型
默默敲代码的徐哥儿10 小时前
八股文整理——后端
java·开发语言·spring boot·后端·学习
巴巴媛66610 小时前
STM32学习笔记【32.BKP + RTC】
笔记·stm32·学习