setUsername($username); } if ($password !== null) { $connectionSettings = $connectionSettings->setPassword($password); } $this->client = $mqtt; $mqtt->connect($connectionSettings); } protected function __clone() { } public static function getInstance() { if (static::$instance == null) { static::$instance = new static(); } return static::$instance; } public function subscribe($topic, $callback) { $this->client->subscribe($topic, $callback); } public function publish(string $topic, string $message, int $qos = 0, bool $retain = false) { $this->client->publish($topic, $message, $qos, $retain); } public function loop(bool $keepAlive = true): void { $this->client->loop($keepAlive); } }