ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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.

References ilChatroomAdmin\getDefaultConfiguration(), and null.

Referenced by ilChatroomAdminViewGUI\checkServerConnection().

35  : bool
36  {
37  if ($use_cache && self::$connection_status !== null) {
38  return self::$connection_status;
39  }
40 
41  $connector = new self(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
42  self::$connection_status = $connector->isServerAlive();
43 
44  return self::$connection_status;
45  }
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

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

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

References sendEnterPrivateRoom().

139  {
140  return $this->sendEnterPrivateRoom($scope, $user);
141  }
$scope
Definition: ltiregstart.php:47
+ 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.

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

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

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:66
$message
Definition: xapiexit.php:31
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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  }

◆ isServerAlive()

ilChatroomServerConnector::isServerAlive ( )

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

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

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
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.

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

Referenced by sendKick().

195  {
196  return $this->file_get_contents(
197  $this->settings->getURL('Kick', (string) $scope) . '/' . $user
198  );
199  }
$scope
Definition: ltiregstart.php:47
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.

References sendLeavePrivateRoom().

167  {
168  return $this->sendLeavePrivateRoom($scope, $user);
169  }
$scope
Definition: ltiregstart.php:47
+ 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.

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

205  {
206  return $this->file_get_contents(
207  $this->settings->getURL('Ban', (string) $scope) . '/' . $user
208  );
209  }
$scope
Definition: ltiregstart.php:47
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.

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

157  {
158  return $this->file_get_contents(
159  $this->settings->getURL('ClearMessages', (string) $scope) . '/' . $user
160  );
161  }
$scope
Definition: ltiregstart.php:47
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.

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

127  {
128  return $this->file_get_contents(
129  $this->settings->getURL('CreatePrivateRoom', (string) $scope) .
130  '/' . $user . '/' . rawurlencode($title)
131  );
132  }
$scope
Definition: ltiregstart.php:47
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.

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

Referenced by enterPrivateRoom().

147  {
148  return $this->file_get_contents(
149  $this->settings->getURL('EnterPrivateRoom', (string) $scope) . '/' . $user
150  );
151  }
$scope
Definition: ltiregstart.php:47
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.

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

220  {
221  return $this->file_get_contents(
222  $this->settings->getURL('InvitePrivateRoom', (string) $scope) .
223  '/' . $user . '/' . $invited_id
224  );
225  }
$scope
Definition: ltiregstart.php:47
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.

References kick().

185  {
186  return $this->kick($scope, $user);
187  }
$scope
Definition: ltiregstart.php:47
kick(int $scope, int $user)
Returns kick URL Creates kick URL using given $scope and $query and returns it.
+ 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.

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

Referenced by leavePrivateRoom().

175  {
176  return $this->file_get_contents(
177  $this->settings->getURL('LeavePrivateRoom', (string) $scope) . '/' . $user
178  );
179  }
$scope
Definition: ltiregstart.php:47
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.

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

231  {
232  $query = http_build_query(['message' => $message]);
233 
234  return $this->file_get_contents(
235  $this->settings->getURL('UserConfigChange', null) . '?' . $query
236  );
237  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$message
Definition: xapiexit.php:31
file_get_contents(string $url, ?array $stream_context_params=null)
+ 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.


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