Skip to content

Commit 305fe35

Browse files
authored
Update README and add CHANGELOG (#58)
* Minor code-doc changes * Add changelog * Update README.md * Change author information to real name
1 parent 129cc6f commit 305fe35

File tree

6 files changed

+99
-17
lines changed

6 files changed

+99
-17
lines changed

CHANGELOG.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Changelog
2+
3+
## Version `v1.0.0`
4+
5+
Significant improvements to the architecture, API and design of the library have been part of `v1.0.0`.
6+
Upgrading should be rather simple for most users though, since the public API has not changed a lot
7+
and only in places which are not used too frequently.
8+
9+
A lot of effort has been put into this summary to document as many changes as possible.
10+
It is impossible to give a guarantee about the completeness of this list though.
11+
You should cover your uses of the library with tests yourself as well.
12+
13+
The following summary compares `v0.3.0` to `v1.0.0`.
14+
15+
### Breaking Changes
16+
17+
- The library does now require PHP 7.4 and supports PHP 8.0. This move was made with the clear intention to drop support for PHP 7.4 at some point.
18+
- The primary interface and class of the library have been renamed to StudlyCaps to follow PSR-2:
19+
- `\PhpMqtt\Client\Contracts\MQTTClient` → `\PhpMqtt\Client\Contracts\MqttClient`
20+
- `\PhpMqtt\Client\MQTTClient` → `\PhpMqtt\Client\MqttClient`
21+
- `\PhpMqtt\Client\Exceptions\MQTTClientException` → `\PhpMqtt\Client\Exceptions\MqttClientException`
22+
- Protocol specific logic has been extracted from the `MQTTClient` class to a new interface `\PhpMqtt\Client\Contracts\MessageProcessor` and the respective implementation for MQTT 3.1, `\PhpMqtt\Client\MessageProcessors\Mqtt31MessageProcessor`.
23+
- The `MessageProcessor` is responsible for parsing and building packages on a byte level.
24+
- Splitting the logic from the main class did not only reduce the overall complexity of the class, it also made testing a lot easier and builds a solid foundation for future development and extension by implementing more protocol versions (like MQTT 5).
25+
- Some `protected` properties have been changed to `private` to ensure they are not manipulated outside the offered scope, which is enforced through getters and setters. This change only affects users which actively inherited their own implementation from the library.
26+
- The QoS 2 message flow is now implemented properly and should just work.
27+
28+
#### Connection Settings
29+
30+
- The `$caFile` parameter of the `MQTTClient` constructor as well as the `$username` and `$password` parameters of the `MQTTClient::connect()` method have been moved to the `ConnectionSettings` class.
31+
- The `ConnectionSettings` use fluent setters for configuration now ([see README](README.md)).
32+
- The `ConnectionSettings`` passed to `MQTTClient::connect()` are now validated and may not contain invalid configuration. In case of invalid configuration, a `\PhpMqtt\Client\Exceptions\ConfigurationInvalidException` is thrown.
33+
- Additional TLS options have been added to the `ConnectionSettings` to support more uses cases with secured connections.
34+
35+
#### Methods
36+
37+
- Most methods can now throw a `\PhpMqtt\Client\Exceptions\RepositoryException` if an interaction with the repository fails. This should happen with the `MemoryRepository` only in exceptional situations, but when implementing persisted repositories, this may happen more frequently and should therefore be considered.
38+
- The `MQTTClient::connect()` method had a parameter called `$sendCleanSessionFlag` while the `MqttClient::connect()` method has the same parameter, but called `$useCleanSession`. The parameters `$username` and `$password` have been removed entirely and are now part of the `ConnectionSettings`.
39+
- The method `MQTTClient::close()` has been renamed to `MqttClient::disconnect()`.
40+
- The parameter `$topic` of `MQTTClient::subscribe()` has been renamed to `$topicFilter` to reflect its meaning (which is a topic, but with wildcards). The `$callback` parameter can be `null` now and has `null` as default.
41+
- The parameter `$topic` of `MQTTClient::unsubscribe()` has been renamed to `$topicFilter` as well.
42+
43+
#### Exceptions
44+
45+
- New exceptions have been introduced and old ones were removed. All exceptions inherit from `\PhpMqtt\Client\Exceptions\MqttClientException` as base. You should ensure your calls to methods of the `MqttClient` handle the exceptions appropriately.
46+
- The exception constants previously defined on the `\PhpMqtt\Client\MQTTClient` class have been moved to the respective exception classes. This change only affects you if you used these constants to render detailed exception information for your users.
47+
48+
#### Repositories
49+
50+
- The `\PhpMqtt\Client\Contracts\Repository` interface has been changed significantly and summarizing all changes would be quite hard anyway. We therefore encourage you to have a look at the interface again and update your own implementation(s) of it, if you have any.
51+
52+
#### Logger
53+
54+
- The `\PhpMqtt\Client\Logger` implementation of `Psr\Log\LoggerInterface` does now decorate the log output with details about the MQTT client (format: `MQTT [{host}:{port}] [{clientId}] {message}`).
55+
56+
### Additions
57+
58+
- It is now possible to register event handlers for received messages. In combination with subscriptions without a callback, this allows to use centralized logic for multiple subscriptions. It also can be used for centralized logging, for example.
59+
- A lot of unit and integration tests have been added which cover most parts of the library, especially the non-exception paths.
60+
- All unit tests, integration tests, and the code style are enforced using a GitHub Actions workflow which runs under Ubuntu against multiple MQTT brokers (currently Mosquitto, HiveMQ and EMQ X). Contributing became easier therefore, but we expect that tests are added for changes and additions.
61+
- To run the tests locally, an MQTT broker without authorization needs to run at `localhost:1883` (or the configuration in `phpunit.xml` is changed instead).
62+
- The project is now analyzed using [sonarcloud.io](https://sonarcloud.io/dashboard?id=php-mqtt_client) which helps us keep up the high standards of the library.
63+
64+
#### Methods
65+
66+
- `MqttClient::isConnected()`: returns `true` if a connection is established (socket opened), and `false` otherwise.
67+
- `MqttClient::getReceivedBytes()`: returns the number of raw bytes received from the broker (this includes meta information and not only message contents).
68+
- `MqttClient::getSentBytes()`: returns the number of raw bytes sent to the broker (this includes meta information and not only message contents).
69+
70+
### Removals
71+
72+
_No functionality has been removed in this version._

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) Namoshek <namoshek@gmx.at>
3+
Copyright (c) Marvin Mall <marvin-mall@msn.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@
1111
[![License](https://poser.pugx.org/php-mqtt/client/license)](https://packagist.org/packages/php-mqtt/client)
1212

1313
[`php-mqtt/client`](https://packagist.org/packages/php-mqtt/client) was created by, and is maintained
14-
by [Namoshek](https://github.com/namoshek).
14+
by [Marvin Mall](https://github.com/namoshek).
1515
It allows you to connect to an MQTT broker where you can publish messages and subscribe to topics.
1616
The current implementation supports all QoS levels ([with limitations](#limitations)).
1717

1818
## Installation
1919

20+
The package is available on [packagist.org](https://packagist.org/packages/php-mqtt/client) and can be installed using `composer`:
21+
2022
```bash
2123
composer require php-mqtt/client
2224
```
2325

24-
This library requires PHP version 7.4 or higher.
26+
The package requires PHP version 7.4 or higher.
2527

2628
## Usage
2729

30+
In the following, only a few very basic examples are given. For more elaborate examples, have a look at the
31+
[`php-mqtt/client-examples` repository](https://github.com/php-mqtt/client-examples).
32+
2833
### Publish
2934

30-
A very basic publish example requires only three steps: connect, publish and close
35+
A very basic publish example using QoS 0 requires only three steps: connect, publish and disconnect
3136

3237
```php
3338
$server = 'some-broker.example.com';
@@ -46,9 +51,11 @@ Be also aware that most of the methods can throw exceptions. The above example d
4651

4752
### Subscribe
4853

49-
Subscribing is a little more complex than publishing as it requires to run an event loop:
54+
Subscribing is a little more complex than publishing as it requires to run an event loop which reads, parses and handles messages from the broker:
5055

5156
```php
57+
$server = 'some-broker.example.com';
58+
$port = 1883;
5259
$clientId = 'test-subscriber';
5360

5461
$mqtt = new \PhpMqtt\Client\MqttClient($server, $port, $clientId);
@@ -90,7 +97,7 @@ Lastly, a logger can be passed as sixth parameter. If none is given, a null logg
9097

9198
Example:
9299
```php
93-
$mqtt = new \PhpMqtt\Client\MQTTClient(
100+
$mqtt = new \PhpMqtt\Client\MqttClient(
94101
$server,
95102
$port,
96103
$clientId,
@@ -104,15 +111,19 @@ The `Logger` must implement the `Psr\Log\LoggerInterface`.
104111

105112
### Connection Settings
106113

107-
The `connect()` method of the `MQTTClient` takes two optional parameters:
114+
The `connect()` method of the `MqttClient` takes two optional parameters:
108115
1. A `ConnectionSettings` instance
109116
2. A `boolean` flag indicating whether a clean session should be requested (a random client id does this implicitly)
110117

111118
Example:
112119
```php
113-
$mqtt = new \PhpMqtt\Client\MQTTClient($server, $port, $clientId);
120+
$mqtt = new \PhpMqtt\Client\MqttClient($server, $port, $clientId);
114121

115-
$connectionSettings = new \PhpMqtt\Client\ConnectionSettings();
122+
$connectionSettings = (new \PhpMqtt\Client\ConnectionSettings)
123+
->setConnectTimeout(3)
124+
->setUseTls(true)
125+
->setTlsSelfSignedAllowed(true);
126+
116127
$mqtt->connect($connectionSettings, true);
117128
```
118129

@@ -123,7 +134,7 @@ This also prevents changes to the connection settings after a connection has bee
123134
The following is a complete list of options with their respective default:
124135

125136
```php
126-
$connectionSettings = (new \PhpMqtt\Client\ConnectionSettings())
137+
$connectionSettings = (new \PhpMqtt\Client\ConnectionSettings)
127138
->setUsername(null)
128139
->setPassword(null)
129140
->setConnectTimeout(60)
@@ -147,7 +158,7 @@ $connectionSettings = (new \PhpMqtt\Client\ConnectionSettings())
147158

148159
## Features
149160

150-
- MQTT Versions
161+
- Supported MQTT Versions
151162
- [x] v3 (just don't use v3.1 features like username & password)
152163
- [x] v3.1
153164
- [ ] v3.1.1
@@ -157,11 +168,9 @@ $connectionSettings = (new \PhpMqtt\Client\ConnectionSettings())
157168
- [x] TLS (secured, verifies the peer using a certificate authority file)
158169
- Connect
159170
- [x] Last Will
160-
- [x] Last Will Topic
161-
- [x] Last Will Message
162-
- [x] Required QoS
163171
- [x] Message Retention
164172
- [x] Authentication (username & password)
173+
- [x] TLS encrypted connections
165174
- [ ] Clean Session (can be set and sent, but the client has no persistence for QoS 2 messages)
166175
- Publish
167176
- [x] QoS Level 0

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"license": "MIT",
1212
"authors": [
1313
{
14-
"name": "Namoshek",
15-
"email": "namoshek@gmx.at",
14+
"name": "Marvin Mall",
15+
"email": "marvin-mall@msn.com",
1616
"role": "developer"
1717
}
1818
],

src/ConnectionSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function getResendTimeout(): int
153153
/**
154154
* The keep alive interval is the number of seconds the client will wait without sending a message
155155
* until it sends a keep alive signal (ping) to the broker. The value cannot be less than 1 second
156-
* and may not be higher than 65536 seconds. A reasonable value is 10 seconds (the default).
156+
* and may not be higher than 65535 seconds. A reasonable value is 10 seconds (the default).
157157
*
158158
* @param int $keepAliveInterval
159159
* @return ConnectionSettings

src/Logger.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* Wrapper for another logger. Drops logged messages if no logger is available.
1212
*
13+
* @internal This class is not part of the public API of the library and used internally only.
1314
* @package PhpMqtt\Client
1415
*/
1516
class Logger implements LoggerInterface

0 commit comments

Comments
 (0)