konekt/xtend

Library to support creating extendable, plugin-aware applications

1.2.0 2024-07-15 13:50 UTC

This package is auto-updated.

Last update: 2024-10-15 14:24:34 UTC


README

Tests Packagist version Packagist downloads StyleCI MIT Software License

Requirements

  • PHP 8.2+

Features

  • Registries
  • Hooks

Installation

You can install the package via composer:

composer require konekt/xtend

Usage

Registries

The following example shows a sample registry that holds reference to various PaymentGateway implementations.

Steps:

  1. Create a class
  2. Add the Registry interface
  3. Use the HasRegistry and RequiresClassOrInterface traits
  4. 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);