Lines
100.00%
11 / 11
Methods
100.00%
6 / 6
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| dispatchTenantCreated | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| dispatchTenantSuspended | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| dispatchTenantDeleted | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| dispatchTenantPlanChanged | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | ||
| dispatch | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 24 | class TenantEventDispatcher | |
| 25 | { | |
| 26 | public const string TENANT_CREATED = 'tenant.created'; | |
| 27 | public const string TENANT_SUSPENDED = 'tenant.suspended'; | |
| 28 | public const string TENANT_DELETED = 'tenant.deleted'; | |
| 29 | public const string TENANT_PLAN_CHANGED = 'tenant.plan.changed'; | |
| 30 | ||
| 31 | public function __construct( | |
| 32 | private readonly EventDispatcherInterface $eventDispatcher, | |
| 33 | ) { | |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * @param array<string, mixed> $context | |
| 38 | */ | |
| 39 | public function dispatchTenantCreated(int $tenantId, array $context = []): TenantLifecycleEvent | |
| 40 | { | |
| 41 | return $this->dispatch(self::TENANT_CREATED, $tenantId, $context); | |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * @param array<string, mixed> $context | |
| 46 | */ | |
| 47 | public function dispatchTenantSuspended(int $tenantId, array $context = []): TenantLifecycleEvent | |
| 48 | { | |
| 49 | return $this->dispatch(self::TENANT_SUSPENDED, $tenantId, $context); | |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * @param array<string, mixed> $context | |
| 54 | */ | |
| 55 | public function dispatchTenantDeleted(int $tenantId, array $context = []): TenantLifecycleEvent | |
| 56 | { | |
| 57 | return $this->dispatch(self::TENANT_DELETED, $tenantId, $context); | |
| 58 | } | |
| 59 | ||
| 60 | /** | |
| 61 | * @param array<string, mixed> $context | |
| 62 | */ | |
| 63 | public function dispatchTenantPlanChanged( | |
| 64 | int $tenantId, | |
| 65 | string $oldPlan, | |
| 66 | string $newPlan, | |
| 67 | array $context = [], | |
| 68 | ): TenantLifecycleEvent { | |
| 69 | $eventContext = $context; | |
| 70 | $eventContext['oldPlan'] = $oldPlan; | |
| 71 | $eventContext['newPlan'] = $newPlan; | |
| 72 | ||
| 73 | return $this->dispatch(self::TENANT_PLAN_CHANGED, $tenantId, $eventContext); | |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * @param array<string, mixed> $context | |
| 78 | */ | |
| 79 | private function dispatch(string $eventName, int $tenantId, array $context): TenantLifecycleEvent | |
| 80 | { | |
| 81 | $event = new TenantLifecycleEvent($tenantId, $context); | |
| 82 | $this->eventDispatcher->dispatch($event, $eventName); | |
| 83 | ||
| 84 | return $event; | |
| 85 | } | |
| 86 | } |