在使用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为例) - 灰信网(软件开发博客聚合)