public function addTopic($topic_filter, $qos_max) { Utility::CheckTopicFilter($topic_filter); Utility::CheckQoS($qos_max); $this->topics[$topic_filter] = $qos_max; }
/** * 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 QoS * * @param int $qos 0,1,2 * @throws Exception */ public function setQos($qos) { Utility::CheckQoS($qos); $this->qos = (int) $qos; if ($this->qos > 0) { /* SUBSCRIBE, UNSUBSCRIBE, and PUBLISH (in cases where QoS > 0) Control Packets MUST contain a non-zero 16-bit Packet Identifier [MQTT-2.3.1-1]. */ $this->require_msgid = true; } else { /* A PUBLISH Packet MUST NOT contain a Packet Identifier if its QoS value is set to 0 [MQTT-2.3.1-5]. */ $this->require_msgid = false; } }