From 08a2ba9d8bfbda45cb3232dbbb04fe85d36b082a Mon Sep 17 00:00:00 2001 From: Alexander Cherednikov Date: Wed, 20 Nov 2024 22:23:03 +0300 Subject: [PATCH 1/2] Added ClientInterface --- changelog.md | 4 ++++ src/Client.php | 4 ++-- src/ClientInterface.php | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/ClientInterface.php diff --git a/changelog.md b/changelog.md index dfbd7eb..b9ab699 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# v6.0.2 + +* An extension point has been added for flexibility + # v6.0.0 Since phpcent v6.0.0 we do not maintain CHANGELOG.md file. diff --git a/src/Client.php b/src/Client.php index 3c0cd6c..94f5eec 100644 --- a/src/Client.php +++ b/src/Client.php @@ -9,7 +9,7 @@ * @copyright Copyright (c) 2019 Centrifugal * @license The MIT License (MIT) */ -class Client +class Client implements ClientInterface { private $url; private $apikey; @@ -273,7 +273,7 @@ public function historyRemove($channel) /** * Get all active channels. - * + * * @param string $pattern (optional) * @return mixed */ diff --git a/src/ClientInterface.php b/src/ClientInterface.php new file mode 100644 index 0000000..e80c0a0 --- /dev/null +++ b/src/ClientInterface.php @@ -0,0 +1,14 @@ + Date: Wed, 20 Nov 2024 22:44:26 +0300 Subject: [PATCH 2/2] Added methods --- src/ClientInterface.php | 137 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index e80c0a0..d16cfab 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -11,4 +11,141 @@ */ interface ClientInterface { + /** + * Publish data into channel. + * + * @param string $channel + * @param array $data + * @param boolean $skipHistory (optional) + * + * @return mixed + */ + public function publish($channel, $data, $skipHistory = false); + + /** + * Broadcast the same data into multiple channels. + * + * @param array $channels + * @param array $data + * @param boolean $skipHistory (optional) + * + * @return mixed + */ + public function broadcast($channels, $data, $skipHistory = false); + + /** + * Subscribe user to channel. + * + * @param string $channel + * @param string $user + * @param string $client (optional) + * + * @return mixed + */ + public function subscribe($channel, $user, $client = ''); + + /** + * Unsubscribe user from channel. + * + * @param string $channel + * @param string $user + * @param string $client (optional) + * + * @return mixed + */ + public function unsubscribe($channel, $user, $client = ''); + + /** + * Disconnect user. + * + * @param string $user + * @param string $client (optional) + * + * @return mixed + */ + public function disconnect($user, $client = ''); + + /** + * Get channel presence info. + * + * @param string $channel + * + * @return mixed + */ + public function presence($channel); + + /** + * Get channel presence stats. + * + * @param string $channel + * + * @return mixed + */ + public function presenceStats($channel); + + /** + * Get channel history. + * + * @param string $channel + * @param int $limit (optional) + * @param array $since (optional) + * @param boolean $reverse (optional) + * + * @return mixed + */ + public function history($channel, $limit = 0, $since = array(), $reverse = false); + + /** + * Get all active channels. + * + * @param string $pattern (optional) + * + * @return mixed + */ + public function channels($pattern = ''); + + /** + * Get server info. + * + * @return mixed + */ + public function info(); + + /** + * Sending many commands in one request + * + * @param array $data + * + * @return mixed + */ + public function batch(array $data); + + /** + * Generate connection JWT. See https://centrifugal.dev/docs/server/authentication. + * Keep in mind that this method does not support all claims of Centrifugo JWT connection + * token at this point. You can use any JWT library to generate Centrifugo tokens. + * + * @param string $userId - current user ID as string. + * @param int $exp - time in the future as unix seconds for token expiration. + * @param array $info + * @param array $channels + * @param array $meta + * + * @return string + */ + public function generateConnectionToken($userId, $exp = 0, $info = array(), $channels = array(), $meta = array()); + + /** + * Generate subscription JWT. See https://centrifugal.dev/docs/server/channel_token_auth. + * Keep in mind that this method does not support all claims of Centrifugo JWT subscription + * token at this point. You can use any JWT library to generate Centrifugo tokens. + * + * @param string $userId - current user ID as string. + * @param string $channel - channel token generated for. + * @param int $exp - time in the future as unix seconds for token expiration. + * @param array $info + * + * @return string + */ + public function generateSubscriptionToken($userId, $channel, $exp = 0, $info = array()); }