From 1ed00d07e6d181b0e107c58b0a5ca818414ded73 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Fri, 18 Oct 2024 14:48:13 +0200 Subject: [PATCH 1/6] Wrong typing of the Grant Token endpoint --- examples/GrantToken.php | 33 ++++++++++++---------- src/PubNub/Endpoints/Access/GrantToken.php | 8 +++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/examples/GrantToken.php b/examples/GrantToken.php index 8609e66a..8eafd636 100644 --- a/examples/GrantToken.php +++ b/examples/GrantToken.php @@ -2,35 +2,38 @@ require_once __DIR__ . '/../vendor/autoload.php'; -use PubNub\Models\Access\Permissions; use PubNub\Models\Consumer\AccessManager\PNAccessManagerTokenResult; - $pnconfig = new \PubNub\PNConfiguration(); -$pnconfig->setPublishKey('my-publish-key'); -$pnconfig->setSubscribeKey('my-subscribe-key'); -$pnconfig->setSecretKey('my-secret-key'); +$pnconfig->setPublishKey(getenv("PUBLISH_PAM_KEY")); +$pnconfig->setSubscribeKey(getenv("SUBSCRIBE_PAM_KEY")); +$pnconfig->setSecretKey(getenv("SECRET_PAM_KEY")); +$pnconfig->setUuid('example-uuid'); $pubnub = new \PubNub\PubNub($pnconfig); try { $token = $pubnub->grantToken() ->ttl(30) - ->authorizedUuid('my-uuid') + ->authorizedUuid('example-uuid') ->addChannelResources([ 'my-channel' => ['read' => true] ]) ->sync(); - /** @var PNAccessManagerTokenResult */ - $parsedToken = $pubnub->parseToken($token); - $parsedToken->getTtl(); - $parsedToken->getChannelResource('my-channel') - ->hasRead(); + print("Token granted: $token\n"); + + /** @var PNAccessManagerTokenResult */ + $parsedToken = $pubnub->parseToken($token); + + $tokensTTL = $parsedToken->getTtl(); + $tokensMyChannelRead = $parsedToken->getChannelResource('my-channel')->hasRead(); + $tokensMyChannelWrite = $parsedToken->getChannelResource('my-channel')->hasWrite(); + + print("Token TTL: $tokensTTL\n"); + print("Token My Channel Read: " . (int)$tokensMyChannelRead . "\n"); + print("Token My Channel Write: " . (int)$tokensMyChannelWrite . "\n"); + } catch (\PubNub\Exceptions\PubNubServerException $e) { var_dump($e->getBody()); } - -var_dump( - $pubnub->parseToken($token)->toArray() -); die; diff --git a/src/PubNub/Endpoints/Access/GrantToken.php b/src/PubNub/Endpoints/Access/GrantToken.php index f10b18c7..fbe41a5e 100644 --- a/src/PubNub/Endpoints/Access/GrantToken.php +++ b/src/PubNub/Endpoints/Access/GrantToken.php @@ -237,18 +237,18 @@ public function buildPath() } /** - * @return PNAccessManagerGrantResult + * @return string */ - public function sync(): PNAccessManagerGrantResult + public function sync(): string { return parent::sync(); } /** * @param string $token - * @return : PNAccessManagerGrantResult + * @return : string */ - public function createResponse($response): PNAccessManagerGrantResult + public function createResponse($response): string { return $response['data']['token']; } From a2ff29e3400222c94b9dc7e3b43460fd3a69ff43 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Fri, 18 Oct 2024 14:58:29 +0200 Subject: [PATCH 2/6] linter fixes --- src/PubNub/CryptoModule.php | 2 +- src/PubNub/Endpoints/Access/GrantToken.php | 9 +++++---- .../Consumer/FileSharing/PNGetFileDownloadURLResult.php | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/PubNub/CryptoModule.php b/src/PubNub/CryptoModule.php index 47c71f96..b3b1c2e3 100644 --- a/src/PubNub/CryptoModule.php +++ b/src/PubNub/CryptoModule.php @@ -178,7 +178,7 @@ public function parseInput(string | object $input): string throw new PubNubResponseParsingException("Decryption error: message is not a string or object"); } - if (strlen($input) == '') { + if (trim($input) == '') { throw new PubNubResponseParsingException("Decryption error: message is empty"); } return $input; diff --git a/src/PubNub/Endpoints/Access/GrantToken.php b/src/PubNub/Endpoints/Access/GrantToken.php index fbe41a5e..e128db68 100644 --- a/src/PubNub/Endpoints/Access/GrantToken.php +++ b/src/PubNub/Endpoints/Access/GrantToken.php @@ -2,9 +2,9 @@ namespace PubNub\Endpoints\Access; + use PubNub\Endpoints\Endpoint; use PubNub\Exceptions\PubNubValidationException; -use PubNub\Models\Consumer\AccessManager\PNAccessManagerGrantResult; use PubNub\PubNubUtil; use PubNub\Enums\PNHttpMethod; use PubNub\Enums\PNOperationType; @@ -12,6 +12,7 @@ use PubNub\Models\Consumer\AccessManager\PNAccessManagerTokenResult; use PubNub\PubNubCborDecode; + class GrantToken extends Endpoint { protected const PATH = '/v3/pam/%s/grant'; @@ -239,16 +240,16 @@ public function buildPath() /** * @return string */ - public function sync(): string + public function sync() : string { return parent::sync(); } /** * @param string $token - * @return : string + * @return string */ - public function createResponse($response): string + public function createResponse($response) : string { return $response['data']['token']; } diff --git a/src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php b/src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php index e13fa413..2339b172 100644 --- a/src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php +++ b/src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php @@ -2,6 +2,7 @@ namespace PubNub\Models\Consumer\FileSharing; + class PNGetFileDownloadURLResult { protected string $fileUrl; @@ -13,7 +14,7 @@ public function __construct($result) public function __toString() { - return "Get file URL success with URL: %s" % $this->fileUrl; + return "Get file URL success with URL: {$this->fileUrl}"; } public function getFileUrl() From bbbd74fe1946d20f85bf5497bf393f1f92e63e50 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Sun, 20 Oct 2024 17:52:43 +0200 Subject: [PATCH 3/6] fix errors and bump pubnub.yml --- .pubnub.yml | 90 +++++++++++++++++-------------------------- phpstan-baseline.neon | 10 ----- 2 files changed, 36 insertions(+), 64 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index e6215090..653f5dfb 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -319,25 +319,21 @@ sdks: supported-operating-systems: macOS: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - Mac OS X 10.8 maximum-os-version: - - macOS 11.2.3 + - macOS 15 target-architecture: - arm64 - x86-64 Windows: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - Windows 7 Professional - Windows 7 Enterprise @@ -350,15 +346,13 @@ sdks: - x86-64 Linux: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - - Ubuntu 16.04 LTS + - Ubuntu 20.04 LTS maximum-os-version: - - Ubuntu 18.04 LTS + - Ubuntu 24.04.1 LTS target-architecture: - x86 - x86-64 @@ -387,25 +381,21 @@ sdks: supported-operating-systems: macOS: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - Mac OS X 10.8 maximum-os-version: - - macOS 11.2.3 + - macOS 15 target-architecture: - arm64 - x86-64 Windows: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - Windows 7 Professional - Windows 7 Enterprise @@ -418,15 +408,13 @@ sdks: - x86-64 Linux: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - - Ubuntu 16.04 LTS + - Ubuntu 20.04 LTS maximum-os-version: - - Ubuntu 18.04 LTS + - Ubuntu 24.04.1 LTS target-architecture: - x86 - x86-64 @@ -455,25 +443,21 @@ sdks: supported-operating-systems: macOS: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - Mac OS X 10.8 maximum-os-version: - - macOS 11.2.3 + - macOS 15 target-architecture: - arm64 - x86-64 Windows: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - Windows 7 Professional - Windows 7 Enterprise @@ -486,15 +470,13 @@ sdks: - x86-64 Linux: runtime-version: - - PHP 5.6 - - PHP 7.0 - - PHP 7.1 - - PHP 7.2 - - PHP 7.3 + - PHP 8.1 + - PHP 8.2 + - PHP 8.3 minimum-os-version: - - Ubuntu 16.04 LTS + - Ubuntu 20.04 LTS maximum-os-version: - - Ubuntu 18.04 LTS + - Ubuntu 24.04.1 LTS target-architecture: - x86 - x86-64 diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f9ac3628..b0ff73e0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -460,11 +460,6 @@ parameters: count: 1 path: src/PubNub/Endpoints/Access/GrantToken.php - - - message: "#^PHPDoc tag @return has invalid value \\(\\: PNAccessManagerGrantResult\\)\\: Unexpected token \"\\:\", expected type at offset 47$#" - count: 1 - path: src/PubNub/Endpoints/Access/GrantToken.php - - message: "#^Property PubNub\\\\Endpoints\\\\Access\\\\GrantToken\\:\\:\\$channels has no type specified\\.$#" count: 1 @@ -3145,11 +3140,6 @@ parameters: count: 1 path: src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php - - - message: "#^Method PubNub\\\\Models\\\\Consumer\\\\FileSharing\\\\PNGetFileDownloadURLResult\\:\\:__toString\\(\\) should return string but returns int\\.$#" - count: 1 - path: src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php - - message: "#^Method PubNub\\\\Models\\\\Consumer\\\\FileSharing\\\\PNGetFileDownloadURLResult\\:\\:getFileUrl\\(\\) has no return type specified\\.$#" count: 1 From c26672dda1f4a7752bf7c5a44f4b60e0ea8c264c Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Mon, 21 Oct 2024 10:51:38 +0200 Subject: [PATCH 4/6] Add organization prefix to gh actions --- .github/workflows/commands-handler.yml | 2 +- .github/workflows/release.yml | 4 ++-- .github/workflows/run-tests.yml | 4 ++-- .github/workflows/run-validations.yml | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/commands-handler.yml b/.github/workflows/commands-handler.yml index 48f71d24..51f8668f 100644 --- a/.github/workflows/commands-handler.yml +++ b/.github/workflows/commands-handler.yml @@ -12,7 +12,7 @@ jobs: name: Process command if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true runs-on: - group: Default + group: organization/Default steps: - name: Check referred user id: user-check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4f6123dc..4250dbe2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: name: Check release required if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true runs-on: - group: Default + group: organization/Default outputs: release: ${{ steps.check.outputs.ready }} steps: @@ -31,7 +31,7 @@ jobs: needs: check-release if: needs.check-release.outputs.release == 'true' runs-on: - group: Default + group: organization/Default steps: - name: Checkout repository uses: actions/checkout@v4 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e5f5cae7..ef51f81c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,7 +14,7 @@ jobs: tests: name: Integration and Unit tests runs-on: - group: Default + group: organization/Default strategy: max-parallel: 1 fail-fast: true @@ -69,7 +69,7 @@ jobs: name: Tests needs: [tests] runs-on: - group: Default + group: organization/Default steps: - name: Tests summary run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed" diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index 42aae75f..e9ad0e54 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -14,7 +14,7 @@ jobs: lint-project: name: "Lint project" runs-on: - group: Default + group: organization/Default strategy: max-parallel: 1 fail-fast: true @@ -64,7 +64,7 @@ jobs: pubnub-yml: name: "Validate .pubnub.yml" runs-on: - group: Default + group: organization/Default steps: - name: Checkout project uses: actions/checkout@v4 @@ -86,7 +86,7 @@ jobs: name: Validations needs: [pubnub-yml, lint-project] runs-on: - group: Default + group: organization/Default steps: - name: Validations summary run: echo -e "\033[38;2;95;215;0m\033[1mAll validations passed" From 3d2c424b5c638e3f01e442d5e64bcdd0992a6cf9 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Mon, 21 Oct 2024 15:58:31 +0200 Subject: [PATCH 5/6] fix typo in pubnub.yaml and bump php in test matrix --- .github/workflows/run-tests.yml | 2 +- .pubnub.yml | 6 +++--- examples/GrantToken.php | 1 - src/PubNub/Endpoints/Access/GrantToken.php | 6 ++---- .../Consumer/FileSharing/PNGetFileDownloadURLResult.php | 1 - 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ef51f81c..9d870679 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,7 +19,7 @@ jobs: max-parallel: 1 fail-fast: true matrix: - php: [8.0, 8.1, 8.2] + php: [8.1, 8.2, 8.3] env: PUBLISH_KEY: ${{ secrets.SDK_PUB_KEY }} SUBSCRIBE_KEY: ${{ secrets.SDK_SUB_KEY }} diff --git a/.pubnub.yml b/.pubnub.yml index 653f5dfb..45721e9b 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -325,7 +325,7 @@ sdks: minimum-os-version: - Mac OS X 10.8 maximum-os-version: - - macOS 15 + - macOS 15.0.1 target-architecture: - arm64 - x86-64 @@ -387,7 +387,7 @@ sdks: minimum-os-version: - Mac OS X 10.8 maximum-os-version: - - macOS 15 + - macOS 15.0.1 target-architecture: - arm64 - x86-64 @@ -449,7 +449,7 @@ sdks: minimum-os-version: - Mac OS X 10.8 maximum-os-version: - - macOS 15 + - macOS 15.0.1 target-architecture: - arm64 - x86-64 diff --git a/examples/GrantToken.php b/examples/GrantToken.php index 8eafd636..71517fef 100644 --- a/examples/GrantToken.php +++ b/examples/GrantToken.php @@ -33,7 +33,6 @@ print("Token TTL: $tokensTTL\n"); print("Token My Channel Read: " . (int)$tokensMyChannelRead . "\n"); print("Token My Channel Write: " . (int)$tokensMyChannelWrite . "\n"); - } catch (\PubNub\Exceptions\PubNubServerException $e) { var_dump($e->getBody()); } diff --git a/src/PubNub/Endpoints/Access/GrantToken.php b/src/PubNub/Endpoints/Access/GrantToken.php index e128db68..a9d7afe3 100644 --- a/src/PubNub/Endpoints/Access/GrantToken.php +++ b/src/PubNub/Endpoints/Access/GrantToken.php @@ -2,7 +2,6 @@ namespace PubNub\Endpoints\Access; - use PubNub\Endpoints\Endpoint; use PubNub\Exceptions\PubNubValidationException; use PubNub\PubNubUtil; @@ -12,7 +11,6 @@ use PubNub\Models\Consumer\AccessManager\PNAccessManagerTokenResult; use PubNub\PubNubCborDecode; - class GrantToken extends Endpoint { protected const PATH = '/v3/pam/%s/grant'; @@ -240,7 +238,7 @@ public function buildPath() /** * @return string */ - public function sync() : string + public function sync(): string { return parent::sync(); } @@ -249,7 +247,7 @@ public function sync() : string * @param string $token * @return string */ - public function createResponse($response) : string + public function createResponse($response): string { return $response['data']['token']; } diff --git a/src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php b/src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php index 2339b172..54b0fe63 100644 --- a/src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php +++ b/src/PubNub/Models/Consumer/FileSharing/PNGetFileDownloadURLResult.php @@ -2,7 +2,6 @@ namespace PubNub\Models\Consumer\FileSharing; - class PNGetFileDownloadURLResult { protected string $fileUrl; From 769f51b0bee57acd724525f102d9787f57401056 Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Tue, 22 Oct 2024 08:27:09 +0000 Subject: [PATCH 6/6] PubNub SDK 7.0.2 release. --- .pubnub.yml | 13 ++++++++++--- CHANGELOG.md | 9 +++++++++ README.md | 2 +- composer.json | 2 +- src/PubNub/PubNub.php | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 45721e9b..9914039d 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,15 @@ name: php -version: 7.0.1 +version: 7.0.2 schema: 1 scm: github.com/pubnub/php changelog: + - date: 2024-10-22 + version: 7.0.2 + changes: + - type: bug + text: "Fixed wrong type annotation for grant token response value." + - type: improvement + text: "Updated compatibility list." - date: 2024-07-10 version: 7.0.1 changes: @@ -420,8 +427,8 @@ sdks: - x86-64 - distribution-type: library distribution-repository: GitHub release - package-name: php-7.0.1.zip - location: https://github.com/pubnub/php/releases/tag/7.0.1 + package-name: php-7.0.2.zip + location: https://github.com/pubnub/php/releases/tag/7.0.2 requires: - name: rmccue/requests min-version: 1.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ed35e59..dce0839a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 7.0.2 +October 22 2024 + +#### Fixed +- Fixed wrong type annotation for grant token response value. + +#### Modified +- Updated compatibility list. + ## 7.0.1 July 10 2024 diff --git a/README.md b/README.md index f22d4053..eca142b1 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": "7.0.1" + "pubnub/pubnub": "7.0.2" } } ``` diff --git a/composer.json b/composer.json index 8fe0d1df..f73aa6c8 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": "proprietary", - "version": "7.0.1", + "version": "7.0.2", "authors": [ { "name": "PubNub", diff --git a/src/PubNub/PubNub.php b/src/PubNub/PubNub.php index 2cb9839d..f0867bce 100644 --- a/src/PubNub/PubNub.php +++ b/src/PubNub/PubNub.php @@ -57,7 +57,7 @@ class PubNub implements LoggerAwareInterface { - protected const SDK_VERSION = "7.0.1"; + protected const SDK_VERSION = "7.0.2"; protected const SDK_NAME = "PubNub-PHP"; public static $MAX_SEQUENCE = 65535;