function check_name($topic_name) { try { echo "Checking \"{$topic_name}\" ... "; Utility::CheckTopicName($topic_name); echo "[32mPASS[0m"; } catch (Exception $e) { echo "[31mFAILED[0m " . $e->getMessage(); } echo "\n"; }
/** * Will * * @param string $topic Will Topic * @param string $message Will Message * @param int $qos Will QoS * @param int $retain Will Retain * @throws Exception */ public function __construct($topic, $message, $qos = 1, $retain = 0) { /* If the Will Flag is set to 0 the Will QoS and Will Retain fields in the Connect Flags MUST be set to zero and the Will Topic and Will Message fields MUST NOT be present in the payload [MQTT-3.1.2-11]. */ if (!$topic || !$message) { throw new Exception('Topic/Message MUST NOT be empty in Will Message'); } Utility::CheckTopicName($topic); $this->topic = $topic; $this->message = $message; Utility::CheckQoS($qos); $this->qos = (int) $qos; $this->retain = $retain ? 1 : 0; }
/** * Set Topic * * @param string $topic */ public function setTopic($topic) { Utility::CheckTopicName($topic); $this->topic = $topic; }