当前位置: 首页 > article >正文

学习路之TP6 --重写vendor目录下的文件(服务覆盖command---优点:命令前后一致)

学习路之TP6 --重写vendor目录下的文件

  • 一、新建命令文件:
  • 二、复制修改:Server.php
  • 三、新建服务类:WorkmanService.php
  • 四、注册服务
  • 五、运行效果

有需求要重写vendor\topthink\think-worker\src\command\Server.php 以实现修改代码

一、新建命令文件:

app\command\Server.php

php think make:command Server 

二、复制修改:Server.php

复制vendor\topthink\think-worker\src\command\Server.php 内容到app\command\Server.php
注意更改命名空间:namespace app\command;

三、新建服务类:WorkmanService.php

php think make:service WorkmanService

修改继承类:class WorkmanService extends \think\worker\Service

<?php
declare (strict_types = 1);

namespace app\service;

class WorkmanService extends \think\worker\Service
{
    /**
     * 注册服务
     *
     * @return mixed
     */
    public function register()
    {
        parent::register();
    	$this->commands([
            'worker:server'  => '\\app\\command\\Server',
        ]);
    }
}

要被重写的文件:vendor\topthink\think-worker\src\Service.php

namespace think\worker;

use think\Service as BaseService;

class Service extends BaseService
{
    public function register()
    {
        $this->commands([
            'worker'         => '\\think\\worker\\command\\Worker',
            'worker:server'  => '\\think\\worker\\command\\Server',
            'worker:gateway' => '\\think\\worker\\command\\GatewayWorker',
        ]);
    }
}

四、注册服务

app\service.php增加

app\service\WorkmanService::class,

在这里插入图片描述

五、运行效果

php think worker:server
在这里插入图片描述

原文地址:https://blog.csdn.net/hopetomorrow/article/details/146223351
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.kler.cn/a/589282.html

相关文章:

  • PentestGPT 下载
  • 在ArcGIS中对图斑进行自上而下从左往右编号
  • 如何解决ChatGPTplus/pro o1/o3模型无法识别图片或者文件,限制次数?
  • 力扣——排序链表
  • 浅述WinForm 和 WPF 的前景
  • Docker生存手册:安装到服务一本通
  • Part2:基于国内源完成Kubernetes集群部署
  • k8s-dashboard
  • 【学习笔记】【C++】哪些函数不能是虚函数
  • Chart GPT、DeepSeek 辅助学习H3C网络工程师考试(一)
  • rsync 备份 clickhouse
  • 【AI论文】MM-Eureka:基于规则的大规模强化学习探索视觉“啊哈”时刻
  • P1591 阶乘数码
  • 12.16some pro about py model
  • 微软.NET框架下通信技术理解与实践
  • STM32U575RIT6单片机(二)
  • 机器学习扫盲系列(1) - 序
  • 【leetcode hot 100 114】二叉树展开为链表
  • uniapp-x 之useAttrs只读
  • C++ std::list超详细指南:基础实践(手搓list)