- PHP 8.2+
- Registries
- Hooks
You can install the package via composer:
composer require konekt/xtend
The following example shows a sample registry that holds reference to various PaymentGateway implementations.
Steps:
- Create a class
- Add the
Registry
interface - Use the
HasRegistry
andRequiresClassOrInterface
traits - Add the
$requiredInterface
static property, and set the interface
final class PaymentGateways implements Registry
{
use HasRegistry;
use RequiresClassOrInterface;
private static string $requiredInterface = PaymentGateway::class;
}
Having that, other developers can add new payment gateways:
PaymentGateways::add('braintree', BrainTreePaymentGateway::class);