konekt / xtend
库,支持创建可扩展、插件感知的应用程序
1.2.0
2024-07-15 13:50 UTC
Requires
- php: ^8.2
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-15 14:05:23 UTC
README
需求
- PHP 8.2+
特性
- 注册表
- 钩子
安装
您可以通过composer安装此包
composer require konekt/xtend
使用方法
注册表
以下示例展示了一个包含各种PaymentGateway实现引用的示例注册表。
步骤
- 创建一个类
- 添加
Registry
接口 - 使用
HasRegistry
和RequiresClassOrInterface
特性 - 添加
$requiredInterface
静态属性,并设置接口
final class PaymentGateways implements Registry { use HasRegistry; use RequiresClassOrInterface; private static string $requiredInterface = PaymentGateway::class; }
有了这些,其他开发者可以添加新的支付网关
PaymentGateways::add('braintree', BrainTreePaymentGateway::class);