prinsfrank/arithmetic-operations

算术运算实现(加法、减法、乘方、除法等)的接口

v0.1 2022-10-16 18:36 UTC

This package is auto-updated.

Last update: 2024-09-12 00:05:10 UTC


README

这是一个包括算术运算接口的抽象包,可以在'实现'包中实现。

构建自己的实现

如果您想贡献算术运算的实现,可以轻松完成。如果您想在包中实现该接口,需要通过在'require'部分添加它来依赖该包;

composer require prinsfrank/arithmetic-operations

之后,您需要确保packagist理解您正在实现虚拟包'prinsfrank/arithmetic-operations-implementation',并将该包列入虚拟包之下。您可以通过在'provides'部分添加该包来完成此操作。将包推送到packagist后,它应该出现在虚拟包此处

将实现依赖添加到您的composer包中

当您作为包维护者想要让人们选择不同的算术运算实现时,您可以要求'prinsfrank/arithmetic-operations-implementation'作为依赖项。注意末尾的'-implementation'。这是一个所谓的'虚拟包'。

如果您直接依赖了'prinsfrank/arithmetic-operations'包,这将导致只安装接口。相反,使用虚拟包会提示开发者选择一个实现。

虚拟包在packagist上列出为它们的实现列表

当包需要实现时安装实现

当安装需要此包实现的包时,composer将给出错误和选择。例如,在以下命令要求包prinsfrank/measurement-unit时

composer require prinsfrank/measurement-unit

在没有首先安装此包的实现的情况下,将显示以下错误

In PackageDiscoveryTrait.php line 379:
  Could not find a matching version of package prinsfrank/measurement-unit. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable).         
    - prinsfrank/measurement-unit v0.1 requires prinsfrank/arithmetic-operations-implementation ^0.1 -> could not be found in any version, but the following packages provide it:
      - prinsfrank/arithmetic-operations-bcmath BCMath implementation for the prinsfrank/arithmetic-operations interface that provides basic arithme
      - prinsfrank/arithmetic-operations-floating-point Floating point math implementation for the prinsfrank/arithmetic-operations interface that provides
      Consider requiring one of these to satisfy the prinsfrank/arithmetic-operations-implementation requirement.

要修复此问题,请选择建议的包之一,并按照以下方式要求添加您想要的包,其中同时要求两个包

composer require prinsfrank/measurement-unit prinsfrank/arithmetic-operations-floating-point