/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
api/controllers/CentrifugoController.php
71 строка
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace api\controllers; use api\controllers\base\BaseController; use common\helpers\CentrifugoHelper; use Yii; /** * Работа с Centrifugo * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2025 */ class CentrifugoController extends BaseController { /** * {@inheritdoc} */ protected function verbs() { return [ 'channel-name' => ['GET', 'OPTIONS'], 'channel-token' => ['GET', 'OPTIONS'], ]; } /** * @SWG\Get(path="/centrifugo/channel-name", * tags = {"user"}, * summary = "Get centrifugo client channel name", * produces = {"application/json", "application/xml"}, * @SWG\Parameter(in = "header", name = "hub-key", required = true, type = "string", description = "User Hub ID"), * @SWG\Response(response = 200, description = "OK"), * @SWG\Response(response = 401, description = "Unauthorized"), * @SWG\Response(response = 500, description = "Internal Server Error") * ) */ public function actionChannelName() { $channel = CentrifugoHelper::getChannelName(Yii::$app->user->identity->guid); return [ 'channel' => $channel, ]; } /** * @SWG\Get(path="/centrifugo/channel-token", * tags = {"user"}, * summary = "Get centrifugo client token", * produces = {"application/json", "application/xml"}, * @SWG\Parameter(in = "header", name = "hub-key", required = true, type = "string", description = "User Hub ID"), * @SWG\Response(response = 200, description = "OK"), * @SWG\Response(response = 401, description = "Unauthorized"), * @SWG\Response(response = 500, description = "Internal Server Error") * ) */ public function actionChannelToken() { $client = CentrifugoHelper::createClient(); $token = $client->generateConnectionToken(Yii::$app->user->id); $channel = CentrifugoHelper::getChannelName(Yii::$app->user->identity->guid); return [ 'token' => $token, 'channel' => $channel, ]; } }