PHP中替换某个包或某个类

在使用composer组件时,有时候需要对包进行一些自定义修改,有一些教程中写需要修改composer.json,然后发布到Packagist,但如果只是适应自己需求所作的小修改,其实并没有必要发布到Packagist,而这样做也是Packagist不推荐的:

Do not submit forks of existing packages. If you need to test changes to a package that you forked to patch, use VCS Repositories instead. If however it is a real long-term fork you intend on maintaining feel free to submit it.

如果只是适应自己的小修改,fork项目回来后,直接对需要修改的位置进行修改并提交,然后在composer.json加上repositories,并指定fork回来的仓库的地址。

复制代码
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/xxx/database"
    },
]

安装后看到composer输出(这里用hyperf/database做例子)

复制代码
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Removing hyperf/database (v2.2.41)
  - Installing hyperf/database (v2.2.41): Cloning xxxxxxxxx

Reference

如何利用 composer 替换第三方包里的某个类(color-thief-php为例) - 灰信网(软件开发博客聚合)

在Composer中使用自己修改的包 - DevsDawn

相关推荐
星空椰3 小时前
Python 面向对象高级:继承与类定义详解
开发语言·python
白露与泡影3 小时前
2026大厂Java面试题大全!牛客网最新版
java·开发语言
凯瑟琳.奥古斯特3 小时前
高阶子查询题目精炼
开发语言·数据库·python·职场和发展·数据库开发
雪度娃娃3 小时前
转向现代C++——在意为改写的函数添加 override
开发语言·c++
喵星人工作室5 小时前
C++火影忍者1.1.2
开发语言·c++
basketball6165 小时前
C++ 中的 ptrdiff_t 详解
开发语言·c++
月亮邮递员6165 小时前
Markdown语法总结
开发语言·前端·javascript
printfLILEI5 小时前
php中的类与对象以及反序列化
linux·开发语言·php
曹牧5 小时前
C#:主线程能够捕获到子线程中的异常
开发语言·数据库·c#
代码中介商5 小时前
深入解析STL中的stack、queue与priority_queue
开发语言·c++