Bugfix topicmanager

* Unsubscribing wouldn't always remove the subscriber.
This commit is contained in:
Chris 2024-03-11 01:50:34 +01:00
parent 2cbc41d29e
commit d310060309

View File

@ -33,14 +33,15 @@ class TopicManager
public function subscribe(SubscriberInterface $subscriber, array $topics): void
{
$this->subscribers->attach($subscriber);
foreach ($topics as $topic) {
$this->getTopic($topic)->addSubscriber($subscriber);
}
$this->subscribers->attach($subscriber);
}
public function unsubscribe(SubscriberInterface $subscriber, ?array $topics=null): void
{
$this->subscribers->detach($subscriber);
if (!$topics) {
foreach ($this->topics as $topic) {
$topic->removeSubscriber($subscriber);
@ -50,7 +51,6 @@ class TopicManager
foreach ($topics as $topic) {
$this->getTopic($topic)->removeSubscriber($subscriber);
}
$this->subscribers->detach($subscriber);
}
public function getTopicCount(): int