konekt/xtend

库,支持创建可扩展、插件感知的应用程序

1.2.0 2024-07-15 13:50 UTC

This package is auto-updated.

Last update: 2024-09-15 14:05:23 UTC


README

Tests Packagist version Packagist downloads StyleCI MIT Software License

需求

  • PHP 8.2+

特性

  • 注册表
  • 钩子

安装

您可以通过composer安装此包

composer require konekt/xtend

使用方法

注册表

以下示例展示了一个包含各种PaymentGateway实现引用的示例注册表。

步骤

  1. 创建一个类
  2. 添加 Registry 接口
  3. 使用 HasRegistryRequiresClassOrInterface 特性
  4. 添加 $requiredInterface 静态属性,并设置接口
final class PaymentGateways implements Registry
{
    use HasRegistry;
    use RequiresClassOrInterface;
    
    private static string $requiredInterface = PaymentGateway::class;
}

有了这些,其他开发者可以添加新的支付网关

PaymentGateways::add('braintree', BrainTreePaymentGateway::class);