学习路之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

相关推荐
余多多_zZ1 小时前
鸿蒙初学者学习手册(HarmonyOSNext_API14)_UIContext(@ohos.arkui.UIContext (UIContext))
笔记·学习·华为·harmonyos
奕天者3 小时前
C++学习笔记(十六)——函数重载
c++·笔记·学习
埃菲尔铁塔_CV算法3 小时前
C# WPF 基础知识学习(四)
学习·c#·wpf
虾球xz4 小时前
游戏引擎学习第155天
学习·游戏引擎
拾2144 小时前
代码比较功能
学习
虾球xz5 小时前
游戏引擎学习第152天
学习·游戏引擎
虾球xz5 小时前
游戏引擎学习第156天
学习·游戏引擎
Brave heart7 小时前
大语言模型打卡学习DAY1
人工智能·学习·语言模型
新中地GIS开发老师8 小时前
Cesium零基础速成教程:一小时入门Cesium
学习·arcgis·大学生·gis开发·地理信息科学·地信