Lines
100.00%
17 / 17
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| subscriptionRegistered | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 3 | ||
| subscriptionCancelled | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | ||
| 16 | final readonly class BrokerSubscriptions implements SubscriptionListener | |
| 17 | { | |
| 18 | public function __construct( | |
| 19 | private Transport $transport, | |
| 20 | private LoggerInterface $logger, | |
| 21 | ) {} | |
| 22 | ||
| 23 | public function subscriptionRegistered(RegisteredSubscription $subscription): void | |
| 24 | { | |
| 25 | if (!$subscription->kind->isBrokerRouted()) { | |
| 26 | return; | |
| 27 | } | |
| 28 | ||
| 29 | if ($subscription->trigger !== null) { | |
| 30 | $this->transport->send(new SubscribeTrigger($subscription->id, $subscription->scope, $subscription->trigger)); | |
| 31 | ||
| 32 | return; | |
| 33 | } | |
| 34 | ||
| 35 | $this->transport->send(new Subscribe( | |
| 36 | subscriptionId: $subscription->id, | |
| 37 | scope: $subscription->scope, | |
| 38 | kind: $subscription->kind, | |
| 39 | selector: $subscription->selector, | |
| 40 | )); | |
| 41 | } | |
| 42 | ||
| 43 | public function subscriptionCancelled(RegisteredSubscription $subscription): void | |
| 44 | { | |
| 45 | if (!$subscription->kind->isBrokerRouted()) { | |
| 46 | return; | |
| 47 | } | |
| 48 | ||
| 49 | try { | |
| 50 | $this->transport->send(new Unsubscribe($subscription->id)); | |
| 51 | } catch (TransportException $e) { | |
| 52 | $this->logger->debug('Could not unsubscribe; the broker channel is closed', ['exception' => $e, 'subscription' => $subscription->id->value]); | |
| 53 | } | |
| 54 | } | |
| 55 | } |