Skip to content

Commit 416e68d

Browse files
benjamin-tang-pusherfbenevidespusher-ci
authored
add socket id to batch trigger if present (#370)
* add socket id to batch trigger if present * Fix tests on PHP 10+ * Bump to version 7.2.3 --------- Co-authored-by: fbenevides <me@benevides.pro> Co-authored-by: Pusher CI <pusher-ci@pusher.com>
1 parent bcae44e commit 416e68d

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 7.2.3
4+
5+
* [Fixed] Include socket_id in batch trigger if included.
6+
37
## 7.2.2
48

59
* [FIXED] composer.phar file removed from package

src/Pusher.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Pusher implements LoggerAwareInterface, PusherInterface
1919
/**
2020
* @var string Version
2121
*/
22-
public static $VERSION = '7.2.2';
22+
public static $VERSION = '7.2.3';
2323

2424
/**
2525
* @var null|PusherCrypto
@@ -475,8 +475,8 @@ public function triggerAsync($channels, string $event, $data, array $params = []
475475
*/
476476
public function sendToUser(string $user_id, string $event, $data, bool $already_encoded = false): object
477477
{
478-
$this->validate_user_id($user_id);
479-
return $this->trigger(["#server-to-user-$user_id"], $event, $data, [], $already_encoded);
478+
$this->validate_user_id($user_id);
479+
return $this->trigger(["#server-to-user-$user_id"], $event, $data, [], $already_encoded);
480480
}
481481

482482
/**
@@ -492,8 +492,8 @@ public function sendToUser(string $user_id, string $event, $data, bool $already_
492492
*/
493493
public function sendToUserAsync(string $user_id, string $event, $data, bool $already_encoded = false): PromiseInterface
494494
{
495-
$this->validate_user_id($user_id);
496-
return $this->triggerAsync(["#server-to-user-$user_id"], $event, $data, [], $already_encoded);
495+
$this->validate_user_id($user_id);
496+
return $this->triggerAsync(["#server-to-user-$user_id"], $event, $data, [], $already_encoded);
497497
}
498498

499499

@@ -914,7 +914,7 @@ public function authorizeChannel(string $channel, string $socket_id, string $cus
914914
return $response;
915915
}
916916

917-
/**
917+
/**
918918
* Convenience function for presence channel authorization.
919919
*
920920
* Equivalent to authorizeChannel($channel, $socket_id, json_encode(['user_id' => $user_id, 'user_info' => $user_info], JSON_THROW_ON_ERROR))
@@ -1061,7 +1061,7 @@ public function ensure_valid_signature(array $headers, string $body): void
10611061
*/
10621062
private function make_event(array $channels, string $event, $data, array $params = [], ?string $info = null, bool $already_encoded = false): array
10631063
{
1064-
$has_encrypted_channel = false;
1064+
$has_encrypted_channel = false;
10651065
foreach ($channels as $chan) {
10661066
if (PusherCrypto::is_encrypted_channel($chan)) {
10671067
$has_encrypted_channel = true;
@@ -1102,12 +1102,12 @@ private function make_event(array $channels, string $event, $data, array $params
11021102
$post_params['data'] = $data_encoded;
11031103
$channel_values = array_values($channels);
11041104
if (count($channel_values) == 1) {
1105-
$post_params['channel'] = $channel_values[0];
1105+
$post_params['channel'] = $channel_values[0];
11061106
} else {
1107-
$post_params['channels'] = $channel_values;
1107+
$post_params['channels'] = $channel_values;
11081108
}
11091109
if (!is_null($info)) {
1110-
$post_params['info'] = $info;
1110+
$post_params['info'] = $info;
11111111
}
11121112

11131113
return array_merge($post_params, $params);
@@ -1166,9 +1166,10 @@ private function make_trigger_batch_body(array $batch = [], bool $already_encode
11661166
$this->validate_channel($event['channel']);
11671167
if (isset($event['socket_id'])) {
11681168
$this->validate_socket_id($event['socket_id']);
1169+
$batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], ['socket_id' => $event['socket_id']], $event['info'] ?? null, $already_encoded);
1170+
} else {
1171+
$batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], [], $event['info'] ?? null, $already_encoded);
11691172
}
1170-
1171-
$batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], [], $event['info'] ?? null, $already_encoded);
11721173
}
11731174

11741175
try {

tests/acceptance/ChannelQueryTest.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ protected function setUp(): void
2626
public function testChannelInfo(): void
2727
{
2828
$result = $this->pusher->get_channel_info('channel-test');
29-
30-
self::assertObjectHasAttribute('occupied', $result, 'class has occupied attribute');
29+
self::assertNotNull($result->occupied, 'class has occupied attribute');
3130
}
3231

3332
public function testChannelList(): void
@@ -68,8 +67,7 @@ public function testFilterByPrefixOneChannel(): void
6867
public function testUsersInfo(): void
6968
{
7069
$result = $this->pusher->get_users_info('presence-channel-test');
71-
72-
$this->assertObjectHasAttribute('users', $result, 'class has users attribute');
70+
self::assertNotNull($result->users, 'class has users attribute');
7371
}
7472

7573
public function testProvidingInfoParameterWithPrefixQueryFailsForPublicChannel(): void
@@ -115,7 +113,6 @@ public function testChannelListUsingGenericGetAndPrefixParam(): void
115113
public function testSingleChannelInfoUsingGenericGet(): void
116114
{
117115
$result = $this->pusher->get('/channels/channel-test');
118-
119-
self::assertObjectHasAttribute('occupied', $result, 'class has occupied attribute');
116+
self::assertNotNull($result->occupied, 'class has occupied attribute');
120117
}
121118
}

0 commit comments

Comments
 (0)