feat: Introduce event listener registration contract
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -30,6 +30,7 @@ use KTXC\Logger\TenantAwareLogger;
|
||||
use KTXF\Event\DeferredEventProcessorInterface;
|
||||
use KTXF\Event\EventDispatcher;
|
||||
use KTXF\Event\EventDispatcherInterface;
|
||||
use KTXF\Event\EventListenerRegistrarInterface;
|
||||
use KTXF\Event\EventListenerRegistry;
|
||||
use KTXF\Cache\EphemeralCacheInterface;
|
||||
use KTXF\Cache\PersistentCacheInterface;
|
||||
@@ -410,6 +411,7 @@ class Kernel implements KernelInterface
|
||||
|
||||
EventDispatcherInterface::class => \DI\get(EventDispatcher::class),
|
||||
DeferredEventProcessorInterface::class => \DI\get(EventDispatcher::class),
|
||||
EventListenerRegistrarInterface::class => \DI\get(EventListenerRegistry::class),
|
||||
// Ephemeral Cache - for short-lived data (sessions, rate limits, challenges)
|
||||
EphemeralCacheInterface::class => function(ContainerInterface $c) use ($projectDir) {
|
||||
$storeType = $c->has('cache.ephemeral') ? $c->get('cache.ephemeral') : 'file';
|
||||
|
||||
@@ -12,7 +12,7 @@ use KTXC\Service\TenantFirewallLogService;
|
||||
use KTXC\Service\TenantFirewallRuleService;
|
||||
use KTXC\Service\TenantFirewallStatusService;
|
||||
use KTXF\Event\DeliveryMode;
|
||||
use KTXF\Event\EventListenerRegistry;
|
||||
use KTXF\Event\EventListenerRegistrarInterface;
|
||||
use KTXF\Event\SecurityEvent;
|
||||
use KTXF\Module\ModuleBrowserInterface;
|
||||
use KTXF\Module\ModuleConsoleInterface;
|
||||
@@ -26,7 +26,7 @@ use KTXF\Module\ModuleInstanceAbstract;
|
||||
class Module extends ModuleInstanceAbstract implements ModuleConsoleInterface, ModuleBrowserInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EventListenerRegistry $events,
|
||||
private readonly EventListenerRegistrarInterface $events,
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXF\Event;
|
||||
|
||||
interface EventListenerRegistrarInterface
|
||||
{
|
||||
/**
|
||||
* @param class-string $service
|
||||
*/
|
||||
public function listen(
|
||||
string $module,
|
||||
string $event,
|
||||
string $service,
|
||||
string $method,
|
||||
DeliveryMode $delivery = DeliveryMode::Immediate,
|
||||
int $priority = 0,
|
||||
FailurePolicy $failurePolicy = FailurePolicy::Continue,
|
||||
): void;
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace KTXF\Event;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
final class EventListenerRegistry
|
||||
final class EventListenerRegistry implements EventListenerRegistrarInterface
|
||||
{
|
||||
/** @var array<string, list<EventListenerDefinition>> */
|
||||
private array $listeners = [];
|
||||
|
||||
Reference in New Issue
Block a user