Implemented subscription logic
This commit is contained in:
@ -10,17 +10,19 @@ class Topic
|
||||
|
||||
/** @var string Topic name */
|
||||
private string $topic;
|
||||
|
||||
/** @var array<string,Message> */
|
||||
private array $messages = [];
|
||||
|
||||
/** @var int Creation unixtime */
|
||||
private int $created;
|
||||
|
||||
private SubscriptionList $subscribers;
|
||||
private SplObjectStorage $subscribers;
|
||||
|
||||
public function __construct(string $topic)
|
||||
{
|
||||
$this->topic = $topic;
|
||||
$this->subscribers = new SubscriptionList();
|
||||
$this->subscribers = new SplObjectStorage();
|
||||
$this->created = time();
|
||||
}
|
||||
|
||||
@ -31,8 +33,10 @@ class Topic
|
||||
foreach ($this->subscribers as $subscriber) {
|
||||
if ($message->private === true) {
|
||||
// TODO check subscriber access
|
||||
$subscriber->deliver($message);
|
||||
} else {
|
||||
// TODO deliver to subscriber
|
||||
$subscriber->deliver($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,6 +56,16 @@ class Topic
|
||||
return count($this->subscribers);
|
||||
}
|
||||
|
||||
public function addSubscriber(SubscriberInterface $subscriber)
|
||||
{
|
||||
$this->subscribers->attach($subscriber);
|
||||
}
|
||||
|
||||
public function removeSubscriber(SubscriberInterface $subscriber)
|
||||
{
|
||||
$this->subscribers->detach($subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Garbage collect histry
|
||||
*
|
||||
|
Reference in New Issue
Block a user