如何安全地添加到作曲家包中?

时间:2021-09-26 07:15:28

I am using the Composer package Omnipay in my project and I want to add a new class to the package (in my case it is support for a new payment gateway). The naming does not conflict with anything and it follows the same naming and structure conventions as sibling folders. However, when I run composer update it deletes my whole folder of changes even though it didn't need to. Is there a way I can tell composer not to delete that directory?

我在我的项目中使用Composer包Omnipay,我想在包中添加一个新类(在我的例子中,它支持新的支付网关)。命名与任何事物都不冲突,它遵循与兄弟文件夹相同的命名和结构约定。但是,当我运行composer update时,它会删除我的整个更改文件夹,即使它不需要。有没有办法告诉作曲家不要删除该目录?

2 个解决方案

#1


0  

Leave everything under /vendor alone, don't change any files there. You should treat libraries as external dependencies - don't check them into source control or change them in any way. Just reference them in your own code.

将所有内容保留在/ vendor下,不要在那里更改任何文件。您应该将库视为外部依赖项 - 不要将它们检入源代码控制或以任何方式更改它们。只需在您自己的代码中引用它们。

If you need to customize a composer library, you can either work around it in your own code (most PHP libraries support dependency injection, which will let you override any of the libraries' classes), or alternatively you can fork the library on github, then reference your own fork in composer.json, or submit the pull request so everyone can benefit from it.

如果你需要自定义一个编写器库,你可以在你自己的代码中解决它(大多数PHP库支持依赖注入,这将允许你覆盖任何库的类),或者你可以在github上分叉库,然后在composer.json中引用你自己的fork,或者提交pull请求,这样每个人都可以从中受益。

#2


0  

As far as I'm aware, you cannot add to a Composer package as it is external and therefore out of your control. You should treat the packages as libraries only, and add all classes into your own project, ensuring that the packages you need are still set up in your .json file

据我所知,你无法添加到Composer包中,因为它是外部的,因此无法控制。您应该将包视为库,并将所有类添加到您自己的项目中,确保您所需的包仍然在.json文件中设置

#1


0  

Leave everything under /vendor alone, don't change any files there. You should treat libraries as external dependencies - don't check them into source control or change them in any way. Just reference them in your own code.

将所有内容保留在/ vendor下,不要在那里更改任何文件。您应该将库视为外部依赖项 - 不要将它们检入源代码控制或以任何方式更改它们。只需在您自己的代码中引用它们。

If you need to customize a composer library, you can either work around it in your own code (most PHP libraries support dependency injection, which will let you override any of the libraries' classes), or alternatively you can fork the library on github, then reference your own fork in composer.json, or submit the pull request so everyone can benefit from it.

如果你需要自定义一个编写器库,你可以在你自己的代码中解决它(大多数PHP库支持依赖注入,这将允许你覆盖任何库的类),或者你可以在github上分叉库,然后在composer.json中引用你自己的fork,或者提交pull请求,这样每个人都可以从中受益。

#2


0  

As far as I'm aware, you cannot add to a Composer package as it is external and therefore out of your control. You should treat the packages as libraries only, and add all classes into your own project, ensuring that the packages you need are still set up in your .json file

据我所知,你无法添加到Composer包中,因为它是外部的,因此无法控制。您应该将包视为库,并将所有类添加到您自己的项目中,确保您所需的包仍然在.json文件中设置