简体   繁体   English

Composer软件包中的PHP类接口

[英]PHP class Interfaces in Composer packages

I use Composer for dependency management in my PHP project. 我在PHP项目中使用Composer进行依赖项管理。

In a packageA I have ClassA. 在packageA中,我有ClassA。 (file ClassA.php) (文件ClassA.php)

ClassA can use satellite classes, what implements SatelliteInterface. ClassA可以使用实现SatelliteInterface的卫星类。

SatelliteInterface defined in SateliteInterface.php 在SateliteInterface.php中定义的SatelliteInterface

ClassB implements SatelliteInterface and provided in PackageB in the file ClassB.php. ClassB实现SatelliteInterface,并在PackageB中的ClassB.php文件中提供。

ClassC implements SatelliteInterface and provided in PackageC in the file ClassC.php. ClassC实现SatelliteInterface,并在PackageC中的ClassC.php文件中提供。

ClassB and ClassC can be used without ClassA. 无需ClassA即可使用ClassB和ClassC。

In what package I need to put SateliteInterface.php file? 我需要在哪个软件包中放入SateliteInterface.php文件?

What dependencies of the packages will be? 软件包的依赖关系是什么?

Thank you. 谢谢。

I would put the SatelliteInterface into a separate Package D. 我会将SatelliteInterface放入单独的Package D中。

Package B and Package C would require Package D. 程序包B和程序包C需要程序包D。

Package A doesn't require anything if I understand it right, but you could use "suggest" in your package A's composer.json to suggest package B and C. 如果我理解正确的话,包A不需要任何东西,但是您可以在包A的composer.json中使用“建议”来建议包B和C。

Package A requires Package B and Package C. 套餐A需要套餐B和套餐C。

Package B and Package C require a package containing SatelliteInterface. 程序包B和程序包C需要一个包含SatelliteInterface的程序包。

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

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