ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilChatroomServerConnector Class Reference

Class ilChatroomServerConnector. More...

+ Collaboration diagram for ilChatroomServerConnector:

Public Member Functions

 __construct (private readonly ilChatroomServerSettings $settings)
 
 isServerAlive ()
 
 connect (int $scope, int $userId)
 Creates connect URL using given $scope and $userId and returns it. More...
 
 sendCreatePrivateRoom (int $scope, int $user, string $title)
 
 enterPrivateRoom (int $scope, int $user)
 
 sendEnterPrivateRoom (int $scope, int $user)
 
 sendClearMessages (int $scope, int $user)
 
 leavePrivateRoom (int $scope, int $user)
 
 sendLeavePrivateRoom (int $scope, int $user)
 
 sendKick (int $scope, int $user)
 
 kick (int $scope, int $user)
 Returns kick URL Creates kick URL using given $scope and $query and returns it. More...
 
 sendBan (int $scope, int $user)
 
 getSettings ()
 
 sendInviteToPrivateRoom (int $scope, int $user, int $invited_id)
 
 sendUserConfigChange (string $message)
 

Static Public Member Functions

static checkServerConnection (bool $use_cache=true)
 

Protected Member Functions

 file_get_contents (string $url, ?array $stream_context_params=null)
 

Static Protected Attributes

static bool $connection_status = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilChatroomServerConnector::__construct ( private readonly ilChatroomServerSettings  $settings)

Definition at line 31 of file class.ilChatroomServerConnector.php.

32 {
33 }

Member Function Documentation

◆ checkServerConnection()

static ilChatroomServerConnector::checkServerConnection ( bool  $use_cache = true)
static

Definition at line 35 of file class.ilChatroomServerConnector.php.

35 : bool
36 {
37 if ($use_cache && self::$connection_status !== null) {
39 }
40
41 $connector = new self(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
42 self::$connection_status = $connector->isServerAlive();
43
45 }
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable.

References $connection_status, and ilChatroomAdmin\getDefaultConfiguration().

Referenced by ilChatroomAdminViewGUI\checkServerConnection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connect()

ilChatroomServerConnector::connect ( int  $scope,
int  $userId 
)

Creates connect URL using given $scope and $userId and returns it.

Returns
string|false

Definition at line 74 of file class.ilChatroomServerConnector.php.

75 {
76 return $this->file_get_contents(
77 $this->settings->getURL('Connect', (string) $scope) . '/' . $userId
78 );
79 }
file_get_contents(string $url, ?array $stream_context_params=null)
$scope
Definition: ltiregstart.php:51

References file_get_contents(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ enterPrivateRoom()

ilChatroomServerConnector::enterPrivateRoom ( int  $scope,
int  $user 
)
Returns
string|false
Deprecated:
Please use sendEnterPrivateRoom instead

Definition at line 138 of file class.ilChatroomServerConnector.php.

139 {
140 return $this->sendEnterPrivateRoom($scope, $user);
141 }

References sendEnterPrivateRoom().

+ Here is the call graph for this function:

◆ file_get_contents()

ilChatroomServerConnector::file_get_contents ( string  $url,
?array  $stream_context_params = null 
)
protected
Parameters
array | null$stream_context_params
Returns
string|false

Definition at line 85 of file class.ilChatroomServerConnector.php.

86 {
87 $credentials = $this->settings->getAuthKey() . ':' . $this->settings->getAuthSecret();
88 $header =
89 "Connection: close\r\n" .
90 "Content-Type: application/json; charset=utf-8\r\n" .
91 "Authorization: Basic " . base64_encode($credentials);
92
93 $ctx = [
94 'http' => [
95 'method' => 'GET',
96 'header' => $header
97 ],
98 'https' => [
99 'method' => 'GET',
100 'header' => $header
101 ]
102 ];
103
104 if (is_array($stream_context_params)) {
105 $ctx = array_merge_recursive($ctx, $stream_context_params);
106 }
107
108 set_error_handler(static function (int $severity, string $message, string $file, int $line): never {
109 throw new ErrorException($message, $severity, $severity, $file, $line);
110 });
111
112 try {
113 return file_get_contents($url, false, stream_context_create($ctx));
114 } catch (Exception $e) {
115 ilLoggerFactory::getLogger('chatroom')->alert($e->getMessage());
116 } finally {
117 restore_error_handler();
118 }
119
120 return false;
121 }
static getLogger(string $a_component_id)
Get component logger.
$url
Definition: shib_logout.php:68
$message
Definition: xapiexit.php:31

References Vendor\Package\$e, $message, $url, file_get_contents(), ilLoggerFactory\getLogger(), and ILIAS\Repository\settings().

Referenced by connect(), file_get_contents(), isServerAlive(), kick(), sendBan(), sendClearMessages(), sendCreatePrivateRoom(), sendEnterPrivateRoom(), sendInviteToPrivateRoom(), sendLeavePrivateRoom(), and sendUserConfigChange().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSettings()

ilChatroomServerConnector::getSettings ( )

Definition at line 211 of file class.ilChatroomServerConnector.php.

212 {
213 return $this->settings;
214 }
Class ilChatroomServerSettings.

◆ isServerAlive()

ilChatroomServerConnector::isServerAlive ( )

Definition at line 47 of file class.ilChatroomServerConnector.php.

47 : bool
48 {
50 $this->settings->getURL('Heartbeat'),
51 [
52 'http' => [
53 'timeout' => 2
54 ],
55 'https' => [
56 'timeout' => 2
57 ]
58 ]
59 );
60
61 if (false === $response) {
62 return false;
63 }
64
65 $responseObject = json_decode($response, false, 512, JSON_THROW_ON_ERROR);
66
67 return $responseObject instanceof stdClass && ((int) $responseObject->status) === 200;
68 }
$response
Definition: xapitoken.php:93

References $response, file_get_contents(), ILIAS\Repository\int(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ kick()

ilChatroomServerConnector::kick ( int  $scope,
int  $user 
)

Returns kick URL Creates kick URL using given $scope and $query and returns it.

Returns
string|false

Definition at line 194 of file class.ilChatroomServerConnector.php.

195 {
196 return $this->file_get_contents(
197 $this->settings->getURL('Kick', (string) $scope) . '/' . $user
198 );
199 }

References file_get_contents(), and ILIAS\Repository\settings().

Referenced by sendKick().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ leavePrivateRoom()

ilChatroomServerConnector::leavePrivateRoom ( int  $scope,
int  $user 
)
Returns
string|false

Definition at line 166 of file class.ilChatroomServerConnector.php.

167 {
168 return $this->sendLeavePrivateRoom($scope, $user);
169 }

References sendLeavePrivateRoom().

+ Here is the call graph for this function:

◆ sendBan()

ilChatroomServerConnector::sendBan ( int  $scope,
int  $user 
)
Returns
string|false

Definition at line 204 of file class.ilChatroomServerConnector.php.

205 {
206 return $this->file_get_contents(
207 $this->settings->getURL('Ban', (string) $scope) . '/' . $user
208 );
209 }

References file_get_contents(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ sendClearMessages()

ilChatroomServerConnector::sendClearMessages ( int  $scope,
int  $user 
)
Returns
string|false

Definition at line 156 of file class.ilChatroomServerConnector.php.

157 {
158 return $this->file_get_contents(
159 $this->settings->getURL('ClearMessages', (string) $scope) . '/' . $user
160 );
161 }

References file_get_contents(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ sendCreatePrivateRoom()

ilChatroomServerConnector::sendCreatePrivateRoom ( int  $scope,
int  $user,
string  $title 
)
Returns
string|false

Definition at line 126 of file class.ilChatroomServerConnector.php.

127 {
128 return $this->file_get_contents(
129 $this->settings->getURL('CreatePrivateRoom', (string) $scope) .
130 '/' . $user . '/' . rawurlencode($title)
131 );
132 }

References file_get_contents(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ sendEnterPrivateRoom()

ilChatroomServerConnector::sendEnterPrivateRoom ( int  $scope,
int  $user 
)
Returns
string|false

Definition at line 146 of file class.ilChatroomServerConnector.php.

147 {
148 return $this->file_get_contents(
149 $this->settings->getURL('EnterPrivateRoom', (string) $scope) . '/' . $user
150 );
151 }

References file_get_contents(), and ILIAS\Repository\settings().

Referenced by enterPrivateRoom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendInviteToPrivateRoom()

ilChatroomServerConnector::sendInviteToPrivateRoom ( int  $scope,
int  $user,
int  $invited_id 
)
Returns
string|false

Definition at line 219 of file class.ilChatroomServerConnector.php.

220 {
221 return $this->file_get_contents(
222 $this->settings->getURL('InvitePrivateRoom', (string) $scope) .
223 '/' . $user . '/' . $invited_id
224 );
225 }

References file_get_contents(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ sendKick()

ilChatroomServerConnector::sendKick ( int  $scope,
int  $user 
)
Returns
string|false

Definition at line 184 of file class.ilChatroomServerConnector.php.

185 {
186 return $this->kick($scope, $user);
187 }
kick(int $scope, int $user)
Returns kick URL Creates kick URL using given $scope and $query and returns it.

References kick().

+ Here is the call graph for this function:

◆ sendLeavePrivateRoom()

ilChatroomServerConnector::sendLeavePrivateRoom ( int  $scope,
int  $user 
)
Returns
string|false

Definition at line 174 of file class.ilChatroomServerConnector.php.

175 {
176 return $this->file_get_contents(
177 $this->settings->getURL('LeavePrivateRoom', (string) $scope) . '/' . $user
178 );
179 }

References file_get_contents(), and ILIAS\Repository\settings().

Referenced by leavePrivateRoom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendUserConfigChange()

ilChatroomServerConnector::sendUserConfigChange ( string  $message)
Returns
string|false

Definition at line 230 of file class.ilChatroomServerConnector.php.

231 {
232 $query = http_build_query(['message' => $message]);
233
234 return $this->file_get_contents(
235 $this->settings->getURL('UserConfigChange', null) . '?' . $query
236 );
237 }

References $message, file_get_contents(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Field Documentation

◆ $connection_status

bool ilChatroomServerConnector::$connection_status = null
staticprotected

Definition at line 29 of file class.ilChatroomServerConnector.php.

Referenced by checkServerConnection().


The documentation for this class was generated from the following file: