ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDatabaseSetupConfig.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
26 public const DEFAULT_COLLATION = "utf8_general_ci";
27 public const DEFAULT_PATH_TO_DB_DUMP = "./components/ILIAS/setup_/sql/ilias3.sql";
28
29 protected string $type;
30
31 protected string $host;
32
33 protected string $database;
34
35 protected string $collation;
36
37 protected string $user;
38
39 protected string $path_to_db_dump;
40
42
43 public function __construct(
44 string $type,
45 string $host,
46 string $database,
47 string $user,
48 protected ?Password $password = null,
49 protected bool $create_database = true,
50 ?string $collation = null,
51 protected ?int $port = null,
52 ?string $path_to_db_dump = null
53 ) {
54 if (!in_array($type, \ilDBConstants::getInstallableTypes())) {
55 throw new \InvalidArgumentException(
56 "Unknown database type: $type"
57 );
58 }
60 throw new \InvalidArgumentException(
61 "Unknown collation: $collation"
62 );
63 }
64 $this->type = trim($type);
65 $this->host = trim($host);
66 $this->database = trim($database);
67 $this->user = trim($user);
68 $this->collation = $collation ? trim($collation) : self::DEFAULT_COLLATION;
69 $this->path_to_db_dump = $path_to_db_dump ?? self::DEFAULT_PATH_TO_DB_DUMP;
70 }
71
72 public function getType(): string
73 {
74 return $this->type;
75 }
76
77 public function getHost(): string
78 {
79 return $this->host;
80 }
81
82 public function getPort(): ?int
83 {
84 return $this->port;
85 }
86
87 public function getDatabase(): string
88 {
89 return $this->database;
90 }
91
92 public function getCreateDatabase(): bool
93 {
94 return $this->create_database;
95 }
96
97 public function getCollation(): string
98 {
99 return $this->collation;
100 }
101
102 public function getUser(): string
103 {
104 return $this->user;
105 }
106
107 public function getPassword(): ?Password
108 {
109 return $this->password;
110 }
111
112 public function getPathToDBDump(): string
113 {
115 }
116
120 public function toMockIniFile(): \ilIniFile
121 {
122 return new class ($this) extends \ilIniFile {
130 public function readVariable(string $a_group, string $a_var_name): string
131 {
132 if ($a_group !== "db") {
133 throw new \LogicException(
134 "Can only access db-config via this mock."
135 );
136 }
137 switch ($a_var_name) {
138 case "user":
139 return $this->config->getUser();
140 case "host":
141 return $this->config->getHost();
142 case "port":
143 return (string) $this->config->getPort();
144 case "pass":
145 $pw = $this->config->getPassword();
146 return $pw !== null ? $pw->toString() : "";
147 case "name":
148 return $this->config->getDatabase();
149 case "type":
150 return $this->config->getType();
151 default:
152 throw new \LogicException(
153 "Cannot provide variable '$a_var_name'"
154 );
155 }
156 }
157
158 public function __construct(protected ilDatabaseSetupConfig $config)
159 {
160 }
161 public function read(): bool
162 {
163 throw new \LogicException("Just a mock here...");
164 }
165 public function parse(): bool
166 {
167 throw new \LogicException("Just a mock here...");
168 }
169 public function fixIniFile(): never
170 {
171 throw new \LogicException("Just a mock here...");
172 }
173 public function write(): bool
174 {
175 throw new \LogicException("Just a mock here...");
176 }
177 public function show(): string
178 {
179 throw new \LogicException("Just a mock here...");
180 }
181 public function getGroupCount(): int
182 {
183 throw new \LogicException("Just a mock here...");
184 }
185 public function readGroups(): array
186 {
187 throw new \LogicException("Just a mock here...");
188 }
189 public function groupExists(string $a_group_name): bool
190 {
191 throw new \LogicException("Just a mock here...");
192 }
193 public function readGroup(string $a_group_name): array
194 {
195 throw new \LogicException("Just a mock here...");
196 }
197 public function addGroup(string $a_group_name): bool
198 {
199 throw new \LogicException("Just a mock here...");
200 }
201 public function removeGroup(string $a_group_name): bool
202 {
203 throw new \LogicException("Just a mock here...");
204 }
205 public function variableExists(string $a_group, string $a_var_name): bool
206 {
207 throw new \LogicException("Just a mock here...");
208 }
209 public function setVariable(string $a_group_name, string $a_var_name, string $a_var_value): bool
210 {
211 throw new \LogicException("Just a mock here...");
212 }
213 public function error(string $a_errmsg): bool
214 {
215 throw new \LogicException("Just a mock here...");
216 }
217 public function getError(): string
218 {
219 throw new \LogicException("Just a mock here...");
220 }
221 };
222 }
223}
A password is used as part of credentials for authentication.
Definition: Password.php:31
variableExists(string $a_group, string $a_var_name)
returns if a variable exists or not
getError()
show()
returns the content of IniFile
readGroups()
returns an array with the names of all the groups
getGroupCount()
returns number of groups
error(string $a_errmsg)
removeGroup(string $a_group_name)
removes a group
readGroup(string $a_group_name)
returns an associative array of the variables in one group
setVariable(string $a_group_name, string $a_var_name, string $a_var_value)
sets a variable in a group
readVariable(string $a_group, string $a_var_name)
reads a single variable from a group
groupExists(string $a_group_name)
checks if a group exists
addGroup(string $a_group_name)
adds a new group
static getAvailableCollations()
static getInstallableTypes()
toMockIniFile()
Adapter to current database-handling via a mock of \ilIniFile.
__construct(string $type, string $host, string $database, string $user, protected ?Password $password=null, protected bool $create_database=true, ?string $collation=null, protected ?int $port=null, ?string $path_to_db_dump=null)
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
A configuration for the setup.
Definition: Config.php:27