作曲家 "provide" 是做什么的?

What does the composer "provide" do?

我正在使用 Laravel + VueJS 从工作中重新创建一个 POS 系统。我需要安装 sped-nfe 软件包才能在工作系统上使用它。 该软件包需要许多其他软件包才能正常运行,例如 ext-curl、ext-soap、ext-json.

按照说明,我添加了

"nfephp-org/sped-nfe" : "^5.0"

给我的 composer.json。 当我运行composer installcomposer update时,出现如下错误:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - nfephp-org/sped-nfe[v5.0.100, ..., v5.0.122] require ext-soap * -> it is missing from your system. Install or enable PHP's soap extension.
    - Root composer.json requires nfephp-org/sped-nfe ^5.0 -> satisfiable by nfephp-org/sped-nfe[v5.0.100, ..., v5.0.122].

To enable extensions, verify that they are enabled in your .ini files:
    - C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

我正在使用 Windows,但我无权修改我们的本地服务器或实际服务器,我在尝试找到解决我的问题的方法时感到很沮丧 - 几乎每个答案都会告诉我修改我的 php.ini 或使用 sudo apt-get 安装 curl - 我随意决定将以下行添加到我的 composer.json:

"provide": {
    "ext-curl":"*",
    "ext-soap":"*"
},

Et voilà, composer update and composer install 工作顺利。 困扰我的是,根据作曲家的文档,

provide

Map of packages that are provided by this package. This is mostly useful for implementations of common interfaces. A package could depend on some virtual package e.g. psr/logger-implementation, any library that implements this logger interface would list it in provide. Implementors can then be found on Packagist.org.

Using provide with the name of an actual package rather than a virtual one implies that the code of that package is also shipped, in which case replace is generally a better choice. A common convention for packages providing an interface and relying on other packages to provide an implementation (for instance the PSR interfaces) is to use a -implementation suffix for the name of the virtual package corresponding to the interface package.

我没有提供这个包,我只是想要求它,但最终以不同的方式放置它。另外,我试过要求它,但错误仍然存​​在。 这是解决我的问题的好方法还是我应该采取不同的方法?

有什么我应该担心的吗?

有人可以为我解释 'provide' 语法吗?

如果您将包或 PHP 扩展添加到 provide 部分,您告诉作曲家您的包本身或外部系统设置“提供”了这个。依赖解析器对此没有问题。

这不会进一步检查此依赖项是否实际上正确 已解决。 Composer 依赖于您的声明,即这不是谎言;)因此,如果您仅将其添加到 部分而没有 正确提供该程序包,则您无法确定您的应用程序是否正常工作。

在您的示例中:您要安装的包需要 SOAP 扩展。没有它就无法正常工作。如果您无法在您的服务器上安装该扩展程序,则不应使用该程序包。