diff --git a/src/Concerns/OffersHooks.php b/src/Concerns/OffersHooks.php index 5f347e8..4e6a054 100644 --- a/src/Concerns/OffersHooks.php +++ b/src/Concerns/OffersHooks.php @@ -60,7 +60,7 @@ protected function initializeEventHandlers(): void */ public function registerLoopEventHandler(\Closure $callback): MqttClient { - $this->loopEventHandlers->attach($callback); + $this->loopEventHandlers->offsetSet($callback); /** @var MqttClient $this */ return $this; @@ -78,7 +78,7 @@ public function unregisterLoopEventHandler(?\Closure $callback = null): MqttClie if ($callback === null) { $this->loopEventHandlers->removeAll($this->loopEventHandlers); } else { - $this->loopEventHandlers->detach($callback); + $this->loopEventHandlers->offsetUnset($callback); } /** @var MqttClient $this */ @@ -126,7 +126,7 @@ private function runLoopEventHandlers(float $elapsedTime): void */ public function registerPublishEventHandler(\Closure $callback): MqttClient { - $this->publishEventHandlers->attach($callback); + $this->publishEventHandlers->offsetSet($callback); /** @var MqttClient $this */ return $this; @@ -144,7 +144,7 @@ public function unregisterPublishEventHandler(?\Closure $callback = null): MqttC if ($callback === null) { $this->publishEventHandlers->removeAll($this->publishEventHandlers); } else { - $this->publishEventHandlers->detach($callback); + $this->publishEventHandlers->offsetUnset($callback); } /** @var MqttClient $this */ @@ -193,7 +193,7 @@ private function runPublishEventHandlers(string $topic, string $message, ?int $m */ public function registerMessageReceivedEventHandler(\Closure $callback): MqttClient { - $this->messageReceivedEventHandlers->attach($callback); + $this->messageReceivedEventHandlers->offsetSet($callback); /** @var MqttClient $this */ return $this; @@ -210,7 +210,7 @@ public function unregisterMessageReceivedEventHandler(?\Closure $callback = null if ($callback === null) { $this->messageReceivedEventHandlers->removeAll($this->messageReceivedEventHandlers); } else { - $this->messageReceivedEventHandlers->detach($callback); + $this->messageReceivedEventHandlers->offsetUnset($callback); } /** @var MqttClient $this */ @@ -260,7 +260,7 @@ private function runMessageReceivedEventHandlers(string $topic, string $message, */ public function registerConnectedEventHandler(\Closure $callback): MqttClient { - $this->connectedEventHandlers->attach($callback); + $this->connectedEventHandlers->offsetSet($callback); /** @var MqttClient $this */ return $this; @@ -277,7 +277,7 @@ public function unregisterConnectedEventHandler(?\Closure $callback = null): Mqt if ($callback === null) { $this->connectedEventHandlers->removeAll($this->connectedEventHandlers); } else { - $this->connectedEventHandlers->detach($callback); + $this->connectedEventHandlers->offsetUnset($callback); } /** @var MqttClient $this */