connection = $connection; } public function getCode() { return 'connect'; } public function start() { $packet = new ConnectRequestPacket(); $packet->setProtocolLevel(self::PROTOCOL_LEVEL); $packet->setProtocolName(self::PROTOCOL_NAME); $packet->setKeepAlive(self::KEEPALIVE); $packet->setFlags(194); $packet->setPayload(zlib_encode($this->connection->toThrift(), ZLIB_ENCODING_DEFLATE, 9)); return $packet; } public function accept(Packet $packet) { return $packet->getPacketType() === Packet::TYPE_CONNACK; } public function next(Packet $packet) { /** @var ConnectResponsePacket $packet */ if ($packet->isSuccess()) { $this->succeed($packet); } else { $this->fail($packet->getErrorName()); } } }