简体   繁体   English

PHP 作曲家,更新时不要丢失 package 代码更改

[英]PHP composer, don't lose package code changes on update

I am working on a project which requires many edits to be made on the required packages.我正在开发一个项目,该项目需要对所需的包进行许多编辑。 Everything works just fine until an update comes on the horizon.一切正常,直到更新即将到来。 Once a package gets updated, all made changes on it are instantly replaced with the newer version(even there is no actual update on the updated file).一旦 package 得到更新,所有对其进行的更改都会立即替换为较新的版本(即使更新的文件没有实际更新)。

My question is, how can I keep my edits over the modified packages and still be able to run composer update without the fear of losing my edits and starting all over again.我的问题是,我怎样才能在修改后的包上保留我的编辑,并且仍然能够运行composer update而不必担心丢失我的编辑并重新开始。

Short answer : You can't.简短的回答:你不能。 The update will always pull the code as it exists in the repository and overwrite the local copy.更新将始终提取存储库中存在的代码并覆盖本地副本。 That's how packages work.这就是包的工作方式。

Longer answer : You can't.更长的答案:你不能。 Editing packages is a bad idea .编辑包是个坏主意 If you find you need to edit the package you are implementing it wrong as there should be no need to modify that code.如果您发现需要编辑 package,则说明您实施错误,因为不需要修改该代码。 If you need additional functionality you can:如果您需要其他功能,您可以:

  1. Add a wrapper .添加一个包装器 Create a class, called a facade, that implements that package but with the changed functionality you desire.创建一个称为外观的 class,它实现了 package,但具有您想要的更改功能。
  2. Fork it and add new functionality and see if it can be added to the package .分叉它并添加新功能,看看它是否可以添加到 package中。 The functionality you desire may be useful to others and could be merged into the package if the author agrees.您想要的功能可能对其他人有用,如果作者同意,可以合并到 package 中。 Then it will exist for all of your future updates.然后它将存在于您未来的所有更新中。
  3. Fork it, make your changes, and include that .分叉它,进行更改,然后将其包含在内 If for some reason the first two options don't work you can make your own fork of the project and put your changes there .如果由于某种原因前两个选项不起作用,您可以制作自己的项目分支并将您的更改放在那里 Then whenever you need to update the package to get the latest code you can create a new fork and migrate/merge your changes to it.然后,每当您需要更新 package 以获取最新代码时,您可以创建一个新的分叉并将您的更改迁移/合并到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM