Skip to content

Commit

Permalink
remove trait
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Apr 21, 2023
1 parent a841f2b commit 7075c2d
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 133 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Run with command ```php subscribe.php start```
**publish.php**
```php
<?php
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
$worker = new Worker();
$worker->onWorkerStart = function(){
Expand Down
60 changes: 30 additions & 30 deletions src/Handle/DecodeV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DecodeV5
{
public static function connect(string $body): array
{
$protocol_name = DecodeTrait::readString($body);
$protocol_name = Decoder::readString($body);
$protocol_level = ord($body[0]);
$clean_session = ord($body[1]) >> 1 & 0x1;
$will_flag = ord($body[1]) >> 2 & 0x1;
Expand All @@ -24,27 +24,27 @@ public static function connect(string $body): array
$password_flag = ord($body[1]) >> 6 & 0x1;
$userName_flag = ord($body[1]) >> 7 & 0x1;
$body = substr($body, 2);
$keepAlive = DecodeTrait::shortInt($body);
$properties_total_length = DecodeTrait::byte($body);
$keepAlive = Decoder::shortInt($body);
$properties_total_length = Decoder::byte($body);
if ($properties_total_length) {
$properties = UnPackProperty::connect($properties_total_length, $body);
}
$clientId = DecodeTrait::readString($body);
$clientId = Decoder::readString($body);
$will_properties = [];
if ($will_flag) {
$will_properties_total_length = DecodeTrait::byte($body);
$will_properties_total_length = Decoder::byte($body);
if ($will_properties_total_length) {
$will_properties = UnPackProperty::willProperties($will_properties_total_length, $body);
}
$will_topic = DecodeTrait::readString($body);
$will_content = DecodeTrait::readString($body);
$will_topic = Decoder::readString($body);
$will_content = Decoder::readString($body);
}
$userName = $password = '';
if ($userName_flag) {
$userName = DecodeTrait::readString($body);
$userName = Decoder::readString($body);
}
if ($password_flag) {
$password = DecodeTrait::readString($body);
$password = Decoder::readString($body);
}

$package = [
Expand Down Expand Up @@ -97,7 +97,7 @@ public static function connAck(string $body): array
'code' => $code,
];

$properties_total_length = DecodeTrait::byte($body);
$properties_total_length = Decoder::byte($body);
if ($properties_total_length) {
$package['properties'] = UnPackProperty::connAck($properties_total_length, $body);
}
Expand All @@ -107,7 +107,7 @@ public static function connAck(string $body): array

public static function publish(int $dup, int $qos, int $retain, string $body): array
{
$topic = DecodeTrait::readString($body);
$topic = Decoder::readString($body);

$package = [
'cmd' => MQTTConst::CMD_PUBLISH,
Expand All @@ -118,10 +118,10 @@ public static function publish(int $dup, int $qos, int $retain, string $body): a
];

if ($qos) {
$package['message_id'] = DecodeTrait::shortInt($body);
$package['message_id'] = Decoder::shortInt($body);
}

$properties_total_length = DecodeTrait::byte($body);
$properties_total_length = Decoder::byte($body);
if ($properties_total_length) {
$package['properties'] = UnPackProperty::publish($properties_total_length, $body);
}
Expand All @@ -133,20 +133,20 @@ public static function publish(int $dup, int $qos, int $retain, string $body): a

public static function subscribe(string $body): array
{
$message_id = DecodeTrait::shortInt($body);
$message_id = Decoder::shortInt($body);
$package = [
'cmd' => MQTTConst::CMD_SUBSCRIBE,
'message_id' => $message_id,
];

$properties_total_length = DecodeTrait::byte($body);
$properties_total_length = Decoder::byte($body);
if ($properties_total_length) {
$package['properties'] = UnPackProperty::subscribe($properties_total_length, $body);
}

$topics = [];
while ($body) {
$topic = DecodeTrait::readString($body);
$topic = Decoder::readString($body);
$topics[$topic] = [
'qos' => ord($body[0]) & 0x3,
'no_local' => (bool) (ord($body[0]) >> 2 & 0x1),
Expand All @@ -163,14 +163,14 @@ public static function subscribe(string $body): array

public static function subAck(string $body): array
{
$message_id = DecodeTrait::shortInt($body);
$message_id = Decoder::shortInt($body);

$package = [
'cmd' => MQTTConst::CMD_SUBACK,
'message_id' => $message_id,
];

$properties_total_length = DecodeTrait::byte($body);
$properties_total_length = Decoder::byte($body);
if ($properties_total_length) {
$package['properties'] = UnPackProperty::pubAndSub($properties_total_length, $body);
}
Expand All @@ -183,21 +183,21 @@ public static function subAck(string $body): array

public static function unSubscribe(string $body): array
{
$message_id = DecodeTrait::shortInt($body);
$message_id = Decoder::shortInt($body);

$package = [
'cmd' => MQTTConst::CMD_UNSUBSCRIBE,
'message_id' => $message_id,
];

$properties_total_length = DecodeTrait::byte($body);
$properties_total_length = Decoder::byte($body);
if ($properties_total_length) {
$package['properties'] = UnPackProperty::unSubscribe($properties_total_length, $body);
}

$topics = [];
while ($body) {
$topic = DecodeTrait::readString($body);
$topic = Decoder::readString($body);
$topics[] = $topic;
}

Expand All @@ -208,14 +208,14 @@ public static function unSubscribe(string $body): array

public static function unSubAck(string $body): array
{
$message_id = DecodeTrait::shortInt($body);
$message_id = Decoder::shortInt($body);

$package = [
'cmd' => MQTTConst::CMD_UNSUBACK,
'message_id' => $message_id,
];

$properties_total_length = DecodeTrait::byte($body);
$properties_total_length = Decoder::byte($body);
if ($properties_total_length) {
$package['properties'] = UnPackProperty::pubAndSub($properties_total_length, $body);
}
Expand All @@ -229,7 +229,7 @@ public static function unSubAck(string $body): array
public static function disconnect(string $body): array
{
if (isset($body[0])) {
$code = DecodeTrait::byte($body);
$code = Decoder::byte($body);
} else {
$code = ReasonCodeConst::NORMAL_DISCONNECTION;
}
Expand All @@ -240,7 +240,7 @@ public static function disconnect(string $body): array

$properties_total_length = 0;
if (isset($body[0])) {
$properties_total_length = DecodeTrait::byte($body);
$properties_total_length = Decoder::byte($body);
}

if ($properties_total_length) {
Expand All @@ -252,10 +252,10 @@ public static function disconnect(string $body): array

public static function getReasonCode(int $cmd, string $body): array
{
$message_id = DecodeTrait::shortInt($body);
$message_id = Decoder::shortInt($body);

if (isset($body[0])) {
$code = DecodeTrait::byte($body);
$code = Decoder::byte($body);
} else {
$code = ReasonCodeConst::SUCCESS;
}
Expand All @@ -268,7 +268,7 @@ public static function getReasonCode(int $cmd, string $body): array

$properties_total_length = 0;
if (isset($body[0])) {
$properties_total_length = DecodeTrait::byte($body);
$properties_total_length = Decoder::byte($body);
}

if ($properties_total_length) {
Expand All @@ -281,7 +281,7 @@ public static function getReasonCode(int $cmd, string $body): array
public static function auth(string $data): array
{
if (isset($data[0])) {
$code = DecodeTrait::byte($data);
$code = Decoder::byte($data);
} else {
$code = ReasonCodeConst::SUCCESS;
}
Expand All @@ -292,7 +292,7 @@ public static function auth(string $data): array

$properties_total_length = 0;
if (isset($data[0])) {
$properties_total_length = DecodeTrait::byte($data);
$properties_total_length = Decoder::byte($data);
}

if ($properties_total_length) {
Expand Down
2 changes: 1 addition & 1 deletion src/Handle/DecodeTrait.php → src/Handle/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Workerman\Mqtt\Consts\MQTTConst;

trait DecodeTrait
class Decoder
{
/**
* Get cmd.
Expand Down
Loading

0 comments on commit 7075c2d

Please sign in to comment.