ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomConfigFileHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
30 private const string CHATROOM_DATA_DIR = '/chatroom/';
31 private const string CHATROOM_CLIENT_CONFIG_FILENAME = 'client.cfg';
32 private const string CHATROOM_SERVER_CONFIG_FILENAME = 'server.cfg';
33
38 public function createClientConfigFile(array $settings): void
39 {
40 $content = $this->getClientFileContent($settings);
41 $this->writeDataToFile($content, self::CHATROOM_CLIENT_CONFIG_FILENAME);
42 }
43
47 protected function getClientFileContent(array $settings): string
48 {
49 global $DIC;
50
51 // Dirty configuration swap: Ilias differentiates between InnoDB and MyISAM.
52 // MyISAM is configured as mysql, InnoDB as innodb.
53 // The client config file only needs information about driver not engine
54 $type = $DIC['ilClientIniFile']->readVariable('db', 'type');
55 if (in_array($type, [
58 ''
59 ], true)) {
60 $type = 'mysql';
61 }
62
63 $settings['database'] = [
64 'type' => $type,
65 'host' => $DIC['ilClientIniFile']->readVariable('db', 'host'),
66 'port' => (int) $DIC['ilClientIniFile']->readVariable('db', 'port'),
67 'name' => $DIC['ilClientIniFile']->readVariable('db', 'name'),
68 'user' => $DIC['ilClientIniFile']->readVariable('db', 'user'),
69 'pass' => $DIC['ilClientIniFile']->readVariable('db', 'pass')
70 ];
71
72 return json_encode($settings, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
73 }
74
79 protected function writeDataToFile(string $content, string $filename): void
80 {
82 $handle = fopen($path . $filename, 'wb');
83
84 if (!fwrite($handle, $content)) {
85 throw new RuntimeException('Cannot write to file');
86 }
87
88 fclose($handle);
89 }
90
95 protected function createDataDirIfNotExists(): string
96 {
98
99 if (!is_dir($path) && !ilFileUtils::makeDir($path)) {
100 throw new RuntimeException('Directory cannot be created');
101 }
102
103 return $path;
104 }
105
110 public function createServerConfigFile(array $settings): void
111 {
112 $content = $this->getServerFileContent($settings);
113 $this->writeDataToFile($content, self::CHATROOM_SERVER_CONFIG_FILENAME);
114 }
115
119 protected function getServerFileContent(array $settings): string
120 {
121 unset($settings['ilias_proxy'], $settings['client_proxy'], $settings['ilias_url'], $settings['client_url']);
122
123 return json_encode($settings, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
124 }
125}
$filename
Definition: buildRTE.php:78
readVariable(string $a_group, string $a_var_name)
reads a single variable from a group
writeDataToFile(string $content, string $filename)
Writes $content to file named by $filename.
createDataDirIfNotExists()
Creates a data directory for configuration files, if the directory does not already exists.
getServerFileContent(array $settings)
Get the server config file contetn as json encoded string.
createClientConfigFile(array $settings)
Creates a client config file and saves it to the chatroom data directory.
getClientFileContent(array $settings)
Get the client config file content as json encoded string.
createServerConfigFile(array $settings)
Creates a server config file and saves it to the chatroom data directory.
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getDataDir()
get data directory (outside webspace)
$path
Definition: ltiservices.php:30
global $DIC
Definition: shib_login.php:26