学习路之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 如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.kler.cn/a/589282.html 如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!