Skip to content

Commit 1bce0b2

Browse files
committed
Merge branch 'master' into update-dependencies
2 parents 5b06d99 + 68c22a1 commit 1bce0b2

26 files changed

+274
-195
lines changed

src/packet/Connect.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
class Connect extends ControlPacket {
1717

18-
/** @var bool */
19-
protected $useVariableHeader = true;
20-
2118
/** @var null|string */
2219
protected $clientId = null;
2320

@@ -156,4 +153,4 @@ public function getClientId()
156153
}
157154
return substr($this->clientId, 0, 23);
158155
}
159-
}
156+
}

src/packet/ConnectionAck.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,14 @@
77

88
namespace oliverlorenz\reactphpmqtt\packet;
99

10-
use oliverlorenz\reactphpmqtt\protocol\Version;
11-
1210
/**
1311
* The CONNACK Packet is the packet sent by the Server in response to
1412
* a CONNECT Packet received from a Client.
1513
*/
1614
class ConnectionAck extends ControlPacket {
1715

18-
protected $useVariableHeader = false;
19-
2016
public static function getControlPacketType()
2117
{
2218
return ControlPacketType::CONNACK;
2319
}
24-
25-
public function __construct(Version $version, $input)
26-
{
27-
$this->version = $version;
28-
$this->input = $input;
29-
}
30-
}
20+
}

src/packet/ControlPacket.php

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,11 @@
1111

1212
abstract class ControlPacket {
1313

14-
protected $command;
15-
1614
/** @var $version Version */
1715
protected $version;
1816

19-
20-
protected $variableHeader;
21-
2217
protected $payload = '';
2318

24-
protected $useVariableHeader = false;
25-
protected $useFixedHeader = true;
26-
2719
protected $identifier;
2820

2921
public function __construct(Version $version)
@@ -38,9 +30,9 @@ public function __construct(Version $version)
3830
*/
3931
public static function parse(Version $version, $rawInput)
4032
{
41-
$packet = new static($version);
4233
static::checkRawInputValidControlPackageType($rawInput);
43-
return $packet;
34+
35+
return new static($version);
4436
}
4537

4638
protected static function checkRawInputValidControlPackageType($rawInput)
@@ -51,9 +43,9 @@ protected static function checkRawInputValidControlPackageType($rawInput)
5143
}
5244
}
5345

54-
/** @return null */
46+
/** @return int */
5547
public static function getControlPacketType() {
56-
throw new \RuntimeException('you should overwrite getControlPacketType()');
48+
throw new \RuntimeException('you must overwrite getControlPacketType()');
5749
}
5850

5951
protected function getPayloadLength()
@@ -91,7 +83,7 @@ protected function getFixedHeader()
9183
*/
9284
protected function getVariableHeader()
9385
{
94-
return null;
86+
return '';
9587
}
9688

9789
/**
@@ -119,27 +111,15 @@ public function getLengthPrefixField($fieldPayload)
119111
$return = chr($msb);
120112
$return .= chr($lsb);
121113
$return .= $fieldPayload;
114+
122115
return $return;
123116
}
124117

125118
public function get()
126119
{
127-
$fullMessage = '';
128-
129-
// add fixed header
130-
if ($this->useFixedHeader) {
131-
$fullMessage .= $this->getFixedHeader();
132-
}
133-
134-
// add variable header
135-
if ($this->useVariableHeader) {
136-
$fullMessage .= $this->getVariableHeader();
137-
}
138-
139-
// add payload
140-
$fullMessage .= $this->getPayload();
141-
142-
return $fullMessage;
120+
return $this->getFixedHeader() .
121+
$this->getVariableHeader() .
122+
$this->getPayload();
143123
}
144124

145125
/**
@@ -161,8 +141,7 @@ protected static function getPayloadLengthPrefixFieldInRawInput($startIndex, $ra
161141
$headerLength = 2;
162142
$header = substr($rawInput, $startIndex, $headerLength);
163143
$lengthOfMessage = ord($header{1});
144+
164145
return substr($rawInput, $startIndex + $headerLength, $lengthOfMessage);
165146
}
166-
167-
168147
}

src/packet/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function getByMessage($version, $input)
2323
$packetControlType = ord($input{0}) >> 4;
2424
switch ($packetControlType) {
2525
case ConnectionAck::getControlPacketType():
26-
return new ConnectionAck($version, $input);
26+
return ConnectionAck::parse($version, $input);
2727
case PingResponse::getControlPacketType():
2828
return new PingResponse($version, $input);
2929
case SubscribeAck::getControlPacketType():

src/packet/PingRequest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
*/
1717
class PingRequest extends ControlPacket {
1818

19-
protected $useVariableHeader = true;
20-
2119
public static function getControlPacketType()
2220
{
2321
return ControlPacketType::PINGREQ;
2422
}
25-
}
23+
}

src/packet/Publish.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class Publish extends ControlPacket {
2525

2626
protected $retain = false;
2727

28-
protected $useVariableHeader = true;
29-
3028
public static function getControlPacketType()
3129
{
3230
return ControlPacketType::PUBLISH;

src/packet/PublishAck.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
*/
1313
class PublishAck extends ControlPacket {
1414

15-
protected $useVariableHeader = true;
16-
1715
public static function getControlPacketType()
1816
{
1917
return ControlPacketType::PUBACK;
2018
}
21-
}
19+
}

src/packet/PublishComplete.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
*/
1414
class PublishComplete extends ControlPacket {
1515

16-
protected $useVariableHeader = true;
17-
1816
public static function getControlPacketType()
1917
{
2018
return ControlPacketType::PUBCOMP;
2119
}
22-
23-
}
20+
}

src/packet/PublishReceived.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
*/
1414
class PublishReceived extends ControlPacket {
1515

16-
protected $useVariableHeader = true;
17-
1816
public static function getControlPacketType()
1917
{
2018
return ControlPacketType::PUBREC;
2119
}
22-
23-
}
20+
}

src/packet/PublishRelease.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
*/
1414
class PublishRelease extends ControlPacket {
1515

16-
protected $useVariableHeader = true;
17-
1816
public static function getControlPacketType()
1917
{
2018
return ControlPacketType::PUBREL;
2119
}
22-
23-
}
20+
}

0 commit comments

Comments
 (0)