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

Added ClientInterface #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright Copyright (c) 2019 Centrifugal
* @license The MIT License (MIT)
*/
class Client
class Client implements ClientInterface
{
private $url;
private $apikey;
Expand Down Expand Up @@ -273,7 +273,7 @@ public function historyRemove($channel)

/**
* Get all active channels.
*
*
* @param string $pattern (optional)
* @return mixed
*/
Expand Down
151 changes: 151 additions & 0 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

namespace phpcent;

/**
* Centrifugo API Client
*
* @package phpcent
* @copyright Copyright (c) 2019 Centrifugal
* @license The MIT License (MIT)
*/
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());
}