55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?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());
|
|
}
|
|
}
|