# 1.2 升級指南
1.2 版本主要修改了 Client 的構造函數參數和 Protocol 的命名空間。
## Protocol
新增一層`Protocol`,使用`V3`和`V5`來區分 MQTT 協議等級。
同時將`Simps\MQTT\Types`也移動到了`Protocol`下,修改為`Simps\MQTT\Protocol\Types`。
### 1.1
```php
Simps\MQTT\Protocol::pack(array $array)
Simps\MQTT\ProtocolV5::pack(array $array)
Simps\MQTT\ProtocolInterface::MQTT_PROTOCOL_LEVEL_3_1;
Simps\MQTT\Types::CONNECT;
```
### 1.2
```php
Simps\MQTT\Protocol\V3::pack(array $array)
Simps\MQTT\Protocol\V5::pack(array $array)
Simps\MQTT\Protocol\ProtocolInterface::MQTT_PROTOCOL_LEVEL_3_1;
Simps\MQTT\Protocol\Types::CONNECT;
```
## Client
Client 之前是直接傳遞數組參數的,現在改為對象的方式。
### 1.1
```php
use Simps\MQTT\Client;
$config = [
'host' => '127.0.0.1',
'port' => 1883,
'user_name' => '',
'password' => '',
'client_id' => Client::genClientID(),
'keep_alive' => 10,
];
$swooleConfig = [
'open_mqtt_protocol' => true,
'package_max_length' => 2 * 1024 * 1024,
'connect_timeout' => 1.0,
'write_timeout' => 3.0,
'read_timeout' => 0.5,
];
$client = new Client($config, $swooleConfig);
```
### 1.2
```php
use Simps\MQTT\Client;
use Simps\MQTT\Config\ClientConfig;
$config = new ClientConfig();
$config->setUserName('')
->setPassword('')
->setClientId(Client::genClientID())
->setKeepAlive(10);
$swooleConfig = [
'open_mqtt_protocol' => true,
'package_max_length' => 2 * 1024 * 1024,
'connect_timeout' => 1.0,
'write_timeout' => 3.0,
'read_timeout' => 0.5,
];
$config->setSwooleConfig($swooleConfig);
$client = new Client('127.0.0.1', 1883, $config);
// 也可以這樣設置
$config = new ClientConfig([
'userName' => '',
'password' => '',
'clientId' => '',
'keepAlive' => 10,
'protocolName' => 'MQTT',
'protocolLevel' => 4,
'properties' => [],
'delay' => 3000, // 3s
'swooleConfig' => []
]);
$client = new Client('127.0.0.1', 1883, $config);
```