Skip to content

Commit

Permalink
fix compatibility issues with php8.2 (#80)
Browse files Browse the repository at this point in the history
* fix compatibility issues with php8.2

* Additional note in DEVELOPER.md

* PubNub SDK v6.0.1 release.

---------

Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
seba-aln and pubnub-release-bot authored May 18, 2023
1 parent a571433 commit e14149e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
13 changes: 10 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: php
version: 6.0.0
version: 6.0.1
schema: 1
scm: github.com/pubnub/php
changelog:
- date: 2023-05-18
version: v6.0.1
changes:
- type: bug
text: "Support for Monolog/Monolog@^3.0."
- type: bug
text: "Added replacement for deprecated utf8_decode method."
- date: 2023-02-01
version: v6.0.0
changes:
Expand Down Expand Up @@ -378,8 +385,8 @@ sdks:
- x86-64
- distribution-type: library
distribution-repository: GitHub release
package-name: php-6.0.0.zip
location: https://github.com/pubnub/php/releases/tag/v6.0.0
package-name: php-6.0.1.zip
location: https://github.com/pubnub/php/releases/tag/v6.0.1
requires:
- name: rmccue/requests
min-version: 1.0.0
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v6.0.1
May 18 2023

#### Fixed
- Support for Monolog/Monolog@^3.0.
- Added replacement for deprecated utf8_decode method.

## v6.0.0
February 01 2023

Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can find that PHP support threads and event loop libraries, but all of them
Requests library [https://github.com/rmccue/Requests] is a wrapper over raw cURL requests.

### Monolog (logging library)
We should review Monolog usage and remove the dependency if possible. Developers who don't use composer encountering problems with manual installation, so the better solution is to get rid of this extra dependency and provide another logging solution.
Monolog has been removed from `PubNub` instance and has been replaced by `Psr\Log\NullLogger`. Now any logger that implements `Psr\Log\LoggerInterface` can be used after setting it to existing `PubNub` instance through a `setLogger(LoggerInterface $logger)` method.

## Tests
There are 3 type of tests:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
{
"require": {
<!-- include the latest version from the badge at the top -->
"pubnub/pubnub": "6.0.0"
"pubnub/pubnub": "6.0.1"
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["api", "real-time", "realtime", "real time", "ajax", "push"],
"homepage": "http://www.pubnub.com/",
"license": "MIT",
"version": "6.0.0",
"version": "6.0.1",
"authors": [
{
"name": "PubNub",
Expand All @@ -21,7 +21,7 @@
"psr/log": "^1.1|^2.0|^3.0"
},
"require-dev": {
"monolog/monolog": "^2.8",
"monolog/monolog": "^2.9 || ^3.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.7",
"phpstan/phpstan": "^1.8"
Expand Down
2 changes: 1 addition & 1 deletion src/PubNub/PubNub.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

class PubNub implements LoggerAwareInterface
{
protected const SDK_VERSION = "6.0.0";
protected const SDK_VERSION = "6.0.1";
protected const SDK_NAME = "PubNub-PHP";

public static $MAX_SEQUENCE = 65535;
Expand Down
38 changes: 33 additions & 5 deletions src/PubNub/PubNubUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ public static function signSha256($secret, $signInput)
{
$result = strtr(base64_encode(hash_hmac(
'sha256',
utf8_encode($signInput),
utf8_encode($secret),
self::convertIso8859ToUtf8($signInput),
self::convertIso8859ToUtf8($secret),
true
)), '+/', '-_');

Expand Down Expand Up @@ -229,9 +229,11 @@ public static function fetchPamPermissionsFrom($jsonInput)

public static function isAssoc($arr)
{
if (!is_array($arr)) return false;
if (!is_array($arr)) {
return false;
}

return array_keys($arr) !== range(0, count($arr) -1 );
return array_keys($arr) !== range(0, count($arr) - 1);
}

/**
Expand All @@ -245,12 +247,38 @@ public static function stringEndsWith($string, $suffix)
{
$str_len = strlen($string);
$suffix_len = strlen($suffix);
if ($suffix_len > $str_len) return false;
if ($suffix_len > $str_len) {
return false;
}
return substr_compare($string, $suffix, $str_len - $suffix_len, $suffix_len) === 0;
}

public static function tokenEncode($token)
{
return str_replace('+', '%20', urlencode($token));
}

public static function convertIso8859ToUtf8($iso_string)
{
$iso_string .= $iso_string;
$len = strlen($iso_string);

for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
switch (true) {
case $iso_string[$i] < "\x80":
$iso_string[$j] = $iso_string[$i];
break;
case $iso_string[$i] < "\xC0":
$iso_string[$j] = "\xC2";
$iso_string[++$j] = $iso_string[$i];
break;
default:
$iso_string[$j] = "\xC3";
$iso_string[++$j] = chr(ord($iso_string[$i]) - 64);
break;
}
}

return substr($iso_string, 0, $j);
}
}

0 comments on commit e14149e

Please sign in to comment.