Skip to content

Commit

Permalink
Add DISCONNECT、PUBACK、PUBREC、PUBREL、UNSUBACK
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Feb 24, 2021
1 parent 09f6334 commit 20a78c7
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Message/DisConnect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* This file is part of Simps
*
* @link https://github.com/simps/mqtt
* @contact Lu Fei <lufei@simps.io>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*/

declare(strict_types=1);

namespace Simps\MQTT\Message;

use Simps\MQTT\Hex\ReasonCode;
use Simps\MQTT\Protocol\Types;
use Simps\MQTT\Protocol\V3;
use Simps\MQTT\Protocol\V5;

class DisConnect extends AbstractMessage
{
protected $code = ReasonCode::NORMAL_DISCONNECTION;

public function getCode(): int
{
return $this->code;
}

public function setCode(int $code): self
{
$this->code = $code;

return $this;
}

public function __toString()
{
$buffer = [
'type' => Types::DISCONNECT,
];

if ($this->isMQTT5()) {
$buffer['code'] = $this->getCode();
$buffer['properties'] = $this->getProperties();

return V5::pack($buffer);
}

return V3::pack($buffer);
}
}
67 changes: 67 additions & 0 deletions src/Message/PubAck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of Simps
*
* @link https://github.com/simps/mqtt
* @contact Lu Fei <lufei@simps.io>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*/

declare(strict_types=1);

namespace Simps\MQTT\Message;

use Simps\MQTT\Hex\ReasonCode;
use Simps\MQTT\Protocol\Types;
use Simps\MQTT\Protocol\V3;
use Simps\MQTT\Protocol\V5;

class PubAck extends AbstractMessage
{
protected $messageId = 0;

protected $code = ReasonCode::SUCCESS;

public function getMessageId(): int
{
return $this->messageId;
}

public function setMessageId(int $messageId): self
{
$this->messageId = $messageId;

return $this;
}

public function getCode(): int
{
return $this->code;
}

public function setCode(int $code): self
{
$this->code = $code;

return $this;
}

public function __toString()
{
$buffer = [
'type' => Types::PUBACK,
'message_id' => $this->getMessageId(),
];

if ($this->isMQTT5()) {
$buffer['code'] = $this->getCode();
$buffer['properties'] = $this->getProperties();

return V5::pack($buffer);
}

return V3::pack($buffer);
}
}
67 changes: 67 additions & 0 deletions src/Message/PubComp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of Simps
*
* @link https://github.com/simps/mqtt
* @contact Lu Fei <lufei@simps.io>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*/

declare(strict_types=1);

namespace Simps\MQTT\Message;

use Simps\MQTT\Hex\ReasonCode;
use Simps\MQTT\Protocol\Types;
use Simps\MQTT\Protocol\V3;
use Simps\MQTT\Protocol\V5;

class PubComp extends AbstractMessage
{
protected $messageId = 0;

protected $code = ReasonCode::SUCCESS;

public function getMessageId(): int
{
return $this->messageId;
}

public function setMessageId(int $messageId): self
{
$this->messageId = $messageId;

return $this;
}

public function getCode(): int
{
return $this->code;
}

public function setCode(int $code): self
{
$this->code = $code;

return $this;
}

public function __toString()
{
$buffer = [
'type' => Types::PUBCOMP,
'message_id' => $this->getMessageId(),
];

if ($this->isMQTT5()) {
$buffer['code'] = $this->getCode();
$buffer['properties'] = $this->getProperties();

return V5::pack($buffer);
}

return V3::pack($buffer);
}
}
67 changes: 67 additions & 0 deletions src/Message/PubRec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of Simps
*
* @link https://github.com/simps/mqtt
* @contact Lu Fei <lufei@simps.io>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*/

declare(strict_types=1);

namespace Simps\MQTT\Message;

use Simps\MQTT\Hex\ReasonCode;
use Simps\MQTT\Protocol\Types;
use Simps\MQTT\Protocol\V3;
use Simps\MQTT\Protocol\V5;

class PubRec extends AbstractMessage
{
protected $messageId = 0;

protected $code = ReasonCode::SUCCESS;

public function getMessageId(): int
{
return $this->messageId;
}

public function setMessageId(int $messageId): self
{
$this->messageId = $messageId;

return $this;
}

public function getCode(): int
{
return $this->code;
}

public function setCode(int $code): self
{
$this->code = $code;

return $this;
}

public function __toString()
{
$buffer = [
'type' => Types::PUBREC,
'message_id' => $this->getMessageId(),
];

if ($this->isMQTT5()) {
$buffer['code'] = $this->getCode();
$buffer['properties'] = $this->getProperties();

return V5::pack($buffer);
}

return V3::pack($buffer);
}
}
67 changes: 67 additions & 0 deletions src/Message/PubRel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of Simps
*
* @link https://github.com/simps/mqtt
* @contact Lu Fei <lufei@simps.io>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*/

declare(strict_types=1);

namespace Simps\MQTT\Message;

use Simps\MQTT\Hex\ReasonCode;
use Simps\MQTT\Protocol\Types;
use Simps\MQTT\Protocol\V3;
use Simps\MQTT\Protocol\V5;

class PubRel extends AbstractMessage
{
protected $messageId = 0;

protected $code = ReasonCode::SUCCESS;

public function getMessageId(): int
{
return $this->messageId;
}

public function setMessageId(int $messageId): self
{
$this->messageId = $messageId;

return $this;
}

public function getCode(): int
{
return $this->code;
}

public function setCode(int $code): self
{
$this->code = $code;

return $this;
}

public function __toString()
{
$buffer = [
'type' => Types::PUBREL,
'message_id' => $this->getMessageId(),
];

if ($this->isMQTT5()) {
$buffer['code'] = $this->getCode();
$buffer['properties'] = $this->getProperties();

return V5::pack($buffer);
}

return V3::pack($buffer);
}
}
67 changes: 67 additions & 0 deletions src/Message/UnSubAck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* This file is part of Simps
*
* @link https://github.com/simps/mqtt
* @contact Lu Fei <lufei@simps.io>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*/

declare(strict_types=1);

namespace Simps\MQTT\Message;

use Simps\MQTT\Hex\ReasonCode;
use Simps\MQTT\Protocol\Types;
use Simps\MQTT\Protocol\V3;
use Simps\MQTT\Protocol\V5;

class UnSubAck extends AbstractMessage
{
protected $messageId = 0;

protected $code = ReasonCode::SUCCESS;

public function getMessageId(): int
{
return $this->messageId;
}

public function setMessageId(int $messageId): self
{
$this->messageId = $messageId;

return $this;
}

public function getCode(): int
{
return $this->code;
}

public function setCode(int $code): self
{
$this->code = $code;

return $this;
}

public function __toString()
{
$buffer = [
'type' => Types::UNSUBACK,
'message_id' => $this->getMessageId(),
];

if ($this->isMQTT5()) {
$buffer['code'] = $this->getCode();
$buffer['properties'] = $this->getProperties();

return V5::pack($buffer);
}

return V3::pack($buffer);
}
}

0 comments on commit 20a78c7

Please sign in to comment.