如何“替换”财产工作与作曲家? [英] How does the "replace" property work with composer?

查看:252
本文介绍了如何“替换”财产工作与作曲家?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么替换属性如何与合作伙伴?我已经阅读了作曲家文档,但仍然不明白。搜索更多信息尚未回答我的问题。

So how does the "replace" property work with composer? I have read the composer document but still not understand it. Searching for more info hasn't answered my questions.

当我查看 github上的Laravel/Framework 。我看不到replace将如何工作。有人可以向我解释这是如何工作的吗?

When I look at the composer.json file on Laravel/Framework on github. I can't see how replace will work. Can someone explain to me how this works? And what the variable "self.version" will equal to?

推荐答案

Composer文档提供了两个基本的例子。我将尝试解释:

The Composer documentation gives two basic examples. I'll try to explain:


列出被此包替换的包。这允许你fork一个包,以不同的名称发布它自己的版本号,而需要原始包的包继续使用你的fork,因为它替换了原始包。

Lists packages that are replaced by this package. This allows you to fork a package, publish it under a different name with its own version numbers, while packages requiring the original package continue to work with your fork because it replaces the original package.

假设您的软件使用 original / library other / package 其本身也需要 original / library

Suppose your software uses original/library and other/package, which itself also requires original/library.

现在您认为原始/库需要集成功能,但维护者不会让您的建议发生在他们的包。您决定以 better / library 名称分叉该库,并标记新版本。

Now you think that original/library needs to integrate a feature, but the maintainers won't let your suggestion happen in their package. You decide to fork that library under the name better/library, and tag a new release.

软件。当然应该使用 better / library 开始,所以你需要改为,但 other / package original / library - 代码重复!如何使其他包使用您的更好/库,而不是也分叉,只更改composer.json(您仍然兼容

Back to your software. Of course it should start using better/library, so you require that instead, but that other/package still requires the original/library - code duplication! How can you make that other package to use your better/library instead without also forking it and only changing the composer.json (you are still compatible to that original/library, so it should work)?

composer.json中添加一个替换键 / code>:

"replace": {
    "original/library":"1.*"
}



现在Composer知道你的 / library 原始/库同样好的解决 other / code>。

Now Composer knows that any package from your better/library is equally good as the original/library when it comes to resolving the dependencies of the other/package.


这对包含子包的包也很有用,例如主symfony / symfony包包含所有Symfony组件,也可作为单独的包。

This is also useful for packages that contain sub-packages, for example the main symfony/symfony package contains all the Symfony Components which are also available as individual packages. If you require the main package it will automatically fulfill any requirement of one of the individual components, since it replaces them.

如果你需要主包,它会自动满足单个组件之一的任何要求。 ,一个稍微不同的角度:对于需要某些功能的任何其他组件,需要框架的组件是一个很好的方法。但是如果你需要你的软件中的完整框架和另一个库,后来还需要该框架的一个组件,框架的 replace 声明允许Composer不必请安装该单个组件两次,因为它已包含在完整框架中。

The same rules, a slightly different angle: Requiring components of a framework is a good approach for any other component that needs some feature. But if you require the full framework in your software, and another library, which subsequently also requires a component of that framework, the replace declaration of the framework allows Composer to not have to install that single component twice, because it is already included in the full framework.

这篇关于如何“替换”财产工作与作曲家?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆