Skip to content

Commit 5ce9da8

Browse files
author
Pascal Wacker
committed
fixing php errors and adjusting namespace to PHP7 style
1 parent b5a932a commit 5ce9da8

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

MQTTClient.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Implementation of MQTT 3.1.1 for PHP with SSL support
44
*/
55

6-
namespace karpy47/php-mqtt-client;
6+
namespace pascalwacker\PHPMqttClient;
77

88
class MQTTClient {
99

@@ -79,9 +79,7 @@ class MQTTClient {
7979
* @param string $protocol Which protocol to use
8080
*/
8181
function __construct($address, $port=null, $protocol='tcp'){
82-
if ($this->setConnection($address, $port, $protocol)) {
83-
;
84-
}
82+
$this->setConnection($address, $port, $protocol);
8583
$this->packetId = rand(1,100)*100; // Reduce risk of creating duplicate ids in sequential sessions
8684
}
8785

@@ -225,11 +223,11 @@ public function sendConnect($clientId, $cleanSession=false, $keepAlive=10, $time
225223
// Basic validation of clientid
226224
if(preg_match("/[^0-9a-zA-Z]/",$clientId)) {
227225
$this->debugMessage('ClientId can only contain characters 0-9,a-z,A-Z');
228-
return;
226+
return false;
229227
}
230228
if(strlen($clientId) > 23) {
231229
$this->debugMessage('ClientId max length is 23 characters/numbers');
232-
return;
230+
return false;
233231
}
234232
$this->clientId = $clientId;
235233

@@ -331,7 +329,7 @@ public function sendConnect($clientId, $cleanSession=false, $keepAlive=10, $time
331329
$connectFlags = 0;
332330
if ($this->connectCleanSession) $connectFlags += 0x02;
333331
if ($this->connectWill) {
334-
$connectflags += 0x04;
332+
$connectFlags += 0x04;
335333
if ($this->connectWillQos) $connectFlags += ($this->connectWill << 3);
336334
if ($this->connectWillRetain) $connectFlags += 0x20;
337335
}
@@ -392,7 +390,7 @@ public function sendConnect($clientId, $cleanSession=false, $keepAlive=10, $time
392390
public function sendPublish($topic, $message, $qos = self::MQTT_QOS1) {
393391
if(!$this->isConnected()) return false;
394392

395-
if($qos!=self::MQTT_QOS0 && $qos!=self::MQTT_QOS1) return false;
393+
if(!in_array($qos, array(self::MQTT_QOS0, self::MQTT_QOS1, self::MQTT_QOS2))) return false;
396394

397395
$packetId = $this->getNextPacketId();
398396
$payload = $this->createPayload($topic);
@@ -424,7 +422,8 @@ public function sendPublish($topic, $message, $qos = self::MQTT_QOS1) {
424422
}
425423

426424
// Send PUBREL
427-
$this->sendPubRel($receivedPacketId);
425+
// TODO: find $receivedPacketId
426+
//$this->sendPubRel($receivedPacketId);
428427

429428
// A PUBCOMP packet is expected
430429
$response = $this->waitForPacket(self::MQTT_PUBCOMP, $packetId);
@@ -598,11 +597,12 @@ public function sendPing() {
598597
$this->pingReqTime = time();
599598

600599
// A PINGRESP packet is expected
601-
$response = waitForPacket(self::MQTT_PINGRESP);
602-
if($responseHeader === false) {
600+
$response = $this->waitForPacket(self::MQTT_PINGRESP);
601+
// TODO: get $responseHeader out of response
602+
/*if($responseHeader === false) {
603603
$this->debugMessage('Invalid packet received, expecting PINGRESP');
604604
return false;
605-
}
605+
}*/
606606

607607
return true;
608608
}

composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
2-
"name": "karpy47/php-mqtt-client",
2+
"name": "pascalwacker/php-mqtt-client",
33
"description": "MQTT 3.1.1 library for PHP with TLS support",
44
"keywords": [ "mqtt", "client", "php" ],
55
"version": "1.0.1",
66
"license": "MIT",
77
"authors": [
88
{
9-
"name": "karpy47"
9+
"name": "karpy47" ,
10+
"name": "pascalwacker"
1011
}
1112
],
1213
"autoload": {
1314
"psr-4": {
14-
"karpy47\\php-mqtt-client\\": ""
15+
"pascalwacker\\PHPMqttClient\\": ""
1516
}
1617
},
1718
"minimum-stability": "dev",

0 commit comments

Comments
 (0)