konekt/xtend

Library to support creating extendable, plugin-aware applications

1.1.0 2023-12-01 10:24 UTC

This package is auto-updated.

Last update: 2024-04-30 00:56:58 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);