Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Members and Membership type, status and include objects #114

Merged
merged 9 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: php
version: 7.2.1
version: 7.3.0
schema: 1
scm: github.com/pubnub/php
changelog:
- date: 2025-02-05
version: 7.3.0
changes:
- type: feature
text: "Extended functionality of Channel Members and User Membership. Now it's possible to use fine-grade includes and set member/membership status and type."
- date: 2025-02-03
version: 7.2.1
changes:
Expand Down Expand Up @@ -442,8 +447,8 @@ sdks:
- x86-64
- distribution-type: library
distribution-repository: GitHub release
package-name: php-7.2.1.zip
location: https://github.com/pubnub/php/releases/tag/7.2.1
package-name: php-7.3.0.zip
location: https://github.com/pubnub/php/releases/tag/7.3.0
requires:
- name: rmccue/requests
min-version: 1.0.0
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 7.3.0
February 05 2025

#### Added
- Extended functionality of Channel Members and User Membership. Now it's possible to use fine-grade includes and set member/membership status and type.

## 7.2.1
February 03 2025

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": "7.2.1"
"pubnub/pubnub": "7.3.0"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion 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": "proprietary",
"version": "7.2.1",
"version": "7.3.0",
"authors": [
{
"name": "PubNub",
Expand Down
45 changes: 0 additions & 45 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1371,16 +1371,6 @@ parameters:
count: 1
path: src/PubNub/Endpoints/Objects/Member/GetMembers.php

-
message: "#^Method PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\GetMembers\\:\\:validateParams\\(\\) has no return type specified\\.$#"
count: 1
path: src/PubNub/Endpoints/Objects/Member/GetMembers.php

-
message: "#^PHPDoc tag @throws with type PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\PubNubBuildRequestException is not subtype of Throwable$#"
count: 1
path: src/PubNub/Endpoints/Objects/Member/GetMembers.php

-
message: "#^Property PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\GetMembers\\:\\:\\$include type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -1406,16 +1396,6 @@ parameters:
count: 1
path: src/PubNub/Endpoints/Objects/Member/RemoveMembers.php

-
message: "#^Method PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\RemoveMembers\\:\\:validateParams\\(\\) has no return type specified\\.$#"
count: 1
path: src/PubNub/Endpoints/Objects/Member/RemoveMembers.php

-
message: "#^PHPDoc tag @throws with type PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\PubNubBuildRequestException is not subtype of Throwable$#"
count: 1
path: src/PubNub/Endpoints/Objects/Member/RemoveMembers.php

-
message: "#^Property PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\RemoveMembers\\:\\:\\$include type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1451,16 +1431,6 @@ parameters:
count: 1
path: src/PubNub/Endpoints/Objects/Member/SetMembers.php

-
message: "#^Method PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\SetMembers\\:\\:validateParams\\(\\) has no return type specified\\.$#"
count: 1
path: src/PubNub/Endpoints/Objects/Member/SetMembers.php

-
message: "#^PHPDoc tag @throws with type PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\PubNubBuildRequestException is not subtype of Throwable$#"
count: 1
path: src/PubNub/Endpoints/Objects/Member/SetMembers.php

-
message: "#^Property PubNub\\\\Endpoints\\\\Objects\\\\Member\\\\SetMembers\\:\\:\\$custom type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1501,11 +1471,6 @@ parameters:
count: 1
path: src/PubNub/Endpoints/Objects/Membership/GetMemberships.php

-
message: "#^PHPDoc tag @throws with type PubNub\\\\Endpoints\\\\Objects\\\\Membership\\\\PubNubBuildRequestException is not subtype of Throwable$#"
count: 1
path: src/PubNub/Endpoints/Objects/Membership/GetMemberships.php

-
message: "#^Property PubNub\\\\Endpoints\\\\Objects\\\\Membership\\\\GetMemberships\\:\\:\\$include type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1536,11 +1501,6 @@ parameters:
count: 1
path: src/PubNub/Endpoints/Objects/Membership/RemoveMemberships.php

-
message: "#^PHPDoc tag @throws with type PubNub\\\\Endpoints\\\\Objects\\\\Membership\\\\PubNubBuildRequestException is not subtype of Throwable$#"
count: 1
path: src/PubNub/Endpoints/Objects/Membership/RemoveMemberships.php

-
message: "#^Property PubNub\\\\Endpoints\\\\Objects\\\\Membership\\\\RemoveMemberships\\:\\:\\$channels type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1581,11 +1541,6 @@ parameters:
count: 1
path: src/PubNub/Endpoints/Objects/Membership/SetMemberships.php

-
message: "#^PHPDoc tag @throws with type PubNub\\\\Endpoints\\\\Objects\\\\Membership\\\\PubNubBuildRequestException is not subtype of Throwable$#"
count: 1
path: src/PubNub/Endpoints/Objects/Membership/SetMemberships.php

-
message: "#^Property PubNub\\\\Endpoints\\\\Objects\\\\Membership\\\\SetMemberships\\:\\:\\$channels type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions src/PubNub/Endpoints/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function validateSubscribeKey()
{
$subscribeKey = $this->pubnub->getConfiguration()->getSubscribeKey();

if ($subscribeKey == null || empty($subscribeKey)) {
if (strlen($subscribeKey) === 0) {
throw new PubNubValidationException("Subscribe Key not configured");
}
}
Expand All @@ -142,7 +142,7 @@ protected function validatePublishKey()
{
$publishKey = $this->pubnub->getConfiguration()->getPublishKey();

if ($publishKey == null || empty($publishKey)) {
if (strlen($publishKey) === 0) {
throw new PubNubValidationException("Publish Key not configured");
}
}
Expand Down
103 changes: 41 additions & 62 deletions src/PubNub/Endpoints/Objects/Member/GetMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,60 @@
use PubNub\Enums\PNHttpMethod;
use PubNub\Enums\PNOperationType;
use PubNub\Exceptions\PubNubValidationException;
use PubNub\Models\Consumer\Objects\Member\PNMemberIncludes;
use PubNub\Models\Consumer\Objects\Member\PNMembersResult;
use PubNub\PubNub;

class GetMembers extends ObjectsCollectionEndpoint
{
protected const PATH = "/v2/objects/%s/channels/%s/uuids";

protected bool $endpointAuthRequired = true;
protected string $endpointHttpMethod = PNHttpMethod::GET;
protected int $endpointOperationType = PNOperationType::PNGetMembersOperation;
protected string $endpointName = "GetMembers";

/** @var string */
protected $channel;
protected ?string $channel;

/** @var array */
protected $include = [];
protected array $include = [];

/** @var PNMemberIncludes */
protected ?PNMemberIncludes $includes;

/**
* @param string $ch
* @param PubNub $pubnubInstance
*/
public function __construct(PubNub $pubnubInstance)
{
parent::__construct($pubnubInstance);
$this->endpointConnectTimeout = $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout();
$this->endpointRequestTimeout = $this->pubnub->getConfiguration()->getConnectTimeout();
}

/**
* @param string $channel
* @return $this
*/
public function channel($ch)
public function channel(string $channel): self
{
$this->channel = $ch;
$this->channel = $channel;

return $this;
}

public function include(PNMemberIncludes $includes): self
{
$this->includes = $includes;
return $this;
}

/**
* @param array $include
* @return $this
*/
public function includeFields($include)
public function includeFields(array $include): self
{
$this->include = $include;

Expand All @@ -42,19 +68,20 @@ public function includeFields($include)

/**
* @throws PubNubValidationException
* @return void
*/
protected function validateParams()
{
$this->validateSubscribeKey();

if (!is_string($this->channel)) {
if (empty($this->channel)) {
throw new PubNubValidationException("channel missing");
}
}

/**
* @return string
* @throws PubNubBuildRequestException
* @throws \PubNub\Exceptions\PubNubBuildRequestException
*/
protected function buildData()
{
Expand Down Expand Up @@ -94,8 +121,10 @@ protected function customParams()
{
$params = $this->defaultParams();

if (count($this->include) > 0) {
$includes = [];
if (!empty($this->includes)) {
$params['include'] = (string)$this->includes;
} elseif (count($this->include) > 0) {
$includes = [];

if (array_key_exists("customFields", $this->include)) {
array_push($includes, 'custom');
Expand All @@ -109,10 +138,8 @@ protected function customParams()
array_push($includes, 'uuid');
}

$includesString = implode(",", $includes);

if (strlen($includesString) > 0) {
$params['include'] = $includesString;
if (!empty($includes)) {
$params['include'] = implode(",", $includes);
}
}

Expand Down Expand Up @@ -152,52 +179,4 @@ protected function customParams()

return $params;
}

/**
* @return bool
*/
protected function isAuthRequired()
{
return true;
}

/**
* @return int
*/
protected function getRequestTimeout()
{
return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout();
}

/**
* @return int
*/
protected function getConnectTimeout()
{
return $this->pubnub->getConfiguration()->getConnectTimeout();
}

/**
* @return string PNHttpMethod
*/
protected function httpMethod()
{
return PNHttpMethod::GET;
}

/**
* @return int
*/
protected function getOperationType()
{
return PNOperationType::PNGetMembersOperation;
}

/**
* @return string
*/
protected function getName()
{
return "GetMembers";
}
}
Loading
Loading