Configurations for payment modules
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventPaymentModules;
|
||||
|
||||
use App\EventPaymentModules\Modules\AccountTransferPaymentModule;
|
||||
use App\EventPaymentModules\Modules\UndefinedPaymentModule;
|
||||
|
||||
/**
|
||||
* Zentrale Auflösung Slug -> Zahlungsmodul. Neue Zahlungsarten werden hier eingetragen.
|
||||
* Bewusst statisch + manuelle Instanziierung (kein Container-Binding), passend zum Projektstil.
|
||||
*/
|
||||
class EventPaymentModuleRegistry
|
||||
{
|
||||
/**
|
||||
* Alle registrierten Modul-Klassen. Reihenfolge bestimmt u.a. die Seed-Reihenfolge.
|
||||
*
|
||||
* @var array<int, class-string<EventPaymentModule>>
|
||||
*/
|
||||
private const MODULES = [
|
||||
AccountTransferPaymentModule::class,
|
||||
UndefinedPaymentModule::class,
|
||||
];
|
||||
|
||||
/** @var array<string, EventPaymentModule>|null Lazy gecachte Instanzen (slug => Modul). */
|
||||
private static ?array $instances = null;
|
||||
|
||||
/**
|
||||
* @return array<string, EventPaymentModule>
|
||||
*/
|
||||
public static function all(): array
|
||||
{
|
||||
if (self::$instances === null) {
|
||||
self::$instances = [];
|
||||
foreach (self::MODULES as $moduleClass) {
|
||||
self::$instances[$moduleClass::slug()] = new $moduleClass();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$instances;
|
||||
}
|
||||
|
||||
public static function forSlug(string $slug): ?EventPaymentModule
|
||||
{
|
||||
return self::all()[$slug] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function slugs(): array
|
||||
{
|
||||
return array_keys(self::all());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user