From e14149ebd464c82deefe8db7932511f29b15fd69 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Thu, 18 May 2023 14:40:00 +0200 Subject: [PATCH] fix compatibility issues with php8.2 (#80) * fix compatibility issues with php8.2 * Additional note in DEVELOPER.md * PubNub SDK v6.0.1 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .pubnub.yml | 13 ++++++++++--- CHANGELOG.md | 7 +++++++ DEVELOPER.md | 2 +- README.md | 2 +- composer.json | 4 ++-- src/PubNub/PubNub.php | 2 +- src/PubNub/PubNubUtil.php | 38 +++++++++++++++++++++++++++++++++----- 7 files changed, 55 insertions(+), 13 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 4e7033db..b29a292b 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -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: @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 43365236..d9a3f2d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/DEVELOPER.md b/DEVELOPER.md index e736db97..5167cb5e 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -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: diff --git a/README.md b/README.md index 2f9e2f8e..5a333cf1 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your { "require": { - "pubnub/pubnub": "6.0.0" + "pubnub/pubnub": "6.0.1" } } ``` diff --git a/composer.json b/composer.json index 80cc5761..2515c103 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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" diff --git a/src/PubNub/PubNub.php b/src/PubNub/PubNub.php index be399580..904ca880 100644 --- a/src/PubNub/PubNub.php +++ b/src/PubNub/PubNub.php @@ -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; diff --git a/src/PubNub/PubNubUtil.php b/src/PubNub/PubNubUtil.php index 8a2e009f..493fb644 100755 --- a/src/PubNub/PubNubUtil.php +++ b/src/PubNub/PubNubUtil.php @@ -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 )), '+/', '-_'); @@ -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); } /** @@ -245,7 +247,9 @@ 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; } @@ -253,4 +257,28 @@ 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); + } }