diff --git a/CHANGELOG.md b/CHANGELOG.md index a58f643..05acb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.2.3 + +* [Fixed] Include socket_id in batch trigger if included. + ## 7.2.2 * [FIXED] composer.phar file removed from package diff --git a/src/Pusher.php b/src/Pusher.php index 157de3e..29979dd 100755 --- a/src/Pusher.php +++ b/src/Pusher.php @@ -19,7 +19,7 @@ class Pusher implements LoggerAwareInterface, PusherInterface /** * @var string Version */ - public static $VERSION = '7.2.2'; + public static $VERSION = '7.2.3'; /** * @var null|PusherCrypto @@ -475,8 +475,8 @@ public function triggerAsync($channels, string $event, $data, array $params = [] */ public function sendToUser(string $user_id, string $event, $data, bool $already_encoded = false): object { - $this->validate_user_id($user_id); - return $this->trigger(["#server-to-user-$user_id"], $event, $data, [], $already_encoded); + $this->validate_user_id($user_id); + return $this->trigger(["#server-to-user-$user_id"], $event, $data, [], $already_encoded); } /** @@ -492,8 +492,8 @@ public function sendToUser(string $user_id, string $event, $data, bool $already_ */ public function sendToUserAsync(string $user_id, string $event, $data, bool $already_encoded = false): PromiseInterface { - $this->validate_user_id($user_id); - return $this->triggerAsync(["#server-to-user-$user_id"], $event, $data, [], $already_encoded); + $this->validate_user_id($user_id); + return $this->triggerAsync(["#server-to-user-$user_id"], $event, $data, [], $already_encoded); } @@ -914,7 +914,7 @@ public function authorizeChannel(string $channel, string $socket_id, string $cus return $response; } - /** + /** * Convenience function for presence channel authorization. * * 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 */ private function make_event(array $channels, string $event, $data, array $params = [], ?string $info = null, bool $already_encoded = false): array { - $has_encrypted_channel = false; + $has_encrypted_channel = false; foreach ($channels as $chan) { if (PusherCrypto::is_encrypted_channel($chan)) { $has_encrypted_channel = true; @@ -1102,12 +1102,12 @@ private function make_event(array $channels, string $event, $data, array $params $post_params['data'] = $data_encoded; $channel_values = array_values($channels); if (count($channel_values) == 1) { - $post_params['channel'] = $channel_values[0]; + $post_params['channel'] = $channel_values[0]; } else { - $post_params['channels'] = $channel_values; + $post_params['channels'] = $channel_values; } if (!is_null($info)) { - $post_params['info'] = $info; + $post_params['info'] = $info; } return array_merge($post_params, $params); @@ -1166,9 +1166,10 @@ private function make_trigger_batch_body(array $batch = [], bool $already_encode $this->validate_channel($event['channel']); if (isset($event['socket_id'])) { $this->validate_socket_id($event['socket_id']); + $batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], ['socket_id' => $event['socket_id']], $event['info'] ?? null, $already_encoded); + } else { + $batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], [], $event['info'] ?? null, $already_encoded); } - - $batch[$key] = $this->make_event([$event['channel']], $event['name'], $event['data'], [], $event['info'] ?? null, $already_encoded); } try { diff --git a/tests/acceptance/ChannelQueryTest.php b/tests/acceptance/ChannelQueryTest.php index d56785d..f8af13f 100644 --- a/tests/acceptance/ChannelQueryTest.php +++ b/tests/acceptance/ChannelQueryTest.php @@ -26,8 +26,7 @@ protected function setUp(): void public function testChannelInfo(): void { $result = $this->pusher->get_channel_info('channel-test'); - - self::assertObjectHasAttribute('occupied', $result, 'class has occupied attribute'); + self::assertNotNull($result->occupied, 'class has occupied attribute'); } public function testChannelList(): void @@ -68,8 +67,7 @@ public function testFilterByPrefixOneChannel(): void public function testUsersInfo(): void { $result = $this->pusher->get_users_info('presence-channel-test'); - - $this->assertObjectHasAttribute('users', $result, 'class has users attribute'); + self::assertNotNull($result->users, 'class has users attribute'); } public function testProvidingInfoParameterWithPrefixQueryFailsForPublicChannel(): void @@ -115,7 +113,6 @@ public function testChannelListUsingGenericGetAndPrefixParam(): void public function testSingleChannelInfoUsingGenericGet(): void { $result = $this->pusher->get('/channels/channel-test'); - - self::assertObjectHasAttribute('occupied', $result, 'class has occupied attribute'); + self::assertNotNull($result->occupied, 'class has occupied attribute'); } }