ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDatabaseSetupConfig.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 use ILIAS\Setup;
23 
24 class ilDatabaseSetupConfig implements Setup\Config
25 {
26  public const DEFAULT_COLLATION = "utf8_general_ci";
27  public const DEFAULT_PATH_TO_DB_DUMP = "./setup/sql/ilias3.sql";
28 
29  protected string $type;
30 
31  protected string $host;
32 
33  protected ?int $port = null;
34 
35  protected string $database;
36 
37  protected bool $create_database;
38 
39  protected string $collation;
40 
41  protected string $user;
42 
43  protected ?\ILIAS\Data\Password $password = null;
44 
45  protected string $path_to_db_dump;
46 
48 
49  public function __construct(
50  string $type,
51  string $host,
52  string $database,
53  string $user,
54  Password $password = null,
55  bool $create_database = true,
56  string $collation = null,
57  int $port = null,
58  string $path_to_db_dump = null
59  ) {
60  if (!in_array($type, \ilDBConstants::getInstallableTypes())) {
61  throw new \InvalidArgumentException(
62  "Unknown database type: $type"
63  );
64  }
65  if ($collation && !in_array(trim($collation), \ilDBConstants::getAvailableCollations())) {
66  throw new \InvalidArgumentException(
67  "Unknown collation: $collation"
68  );
69  }
70  $this->type = trim($type);
71  $this->host = trim($host);
72  $this->database = trim($database);
73  $this->user = trim($user);
74  $this->password = $password;
75  $this->create_database = $create_database;
76  $this->collation = $collation ? trim($collation) : self::DEFAULT_COLLATION;
77  $this->port = $port;
78  $this->path_to_db_dump = $path_to_db_dump ?? self::DEFAULT_PATH_TO_DB_DUMP;
79  }
80 
81  public function getType(): string
82  {
83  return $this->type;
84  }
85 
86  public function getHost(): string
87  {
88  return $this->host;
89  }
90 
91  public function getPort(): ?int
92  {
93  return $this->port;
94  }
95 
96  public function getDatabase(): string
97  {
98  return $this->database;
99  }
100 
101  public function getCreateDatabase(): bool
102  {
103  return $this->create_database;
104  }
105 
106  public function getCollation(): string
107  {
108  return $this->collation;
109  }
110 
111  public function getUser(): string
112  {
113  return $this->user;
114  }
115 
116  public function getPassword(): ?Password
117  {
118  return $this->password;
119  }
120 
121  public function getPathToDBDump(): string
122  {
123  return $this->path_to_db_dump;
124  }
125 
129  public function toMockIniFile(): \ilIniFile
130  {
131  return new class ($this) extends \ilIniFile {
139  public function readVariable(string $a_group, string $a_var_name): string
140  {
141  if ($a_group !== "db") {
142  throw new \LogicException(
143  "Can only access db-config via this mock."
144  );
145  }
146  switch ($a_var_name) {
147  case "user":
148  return $this->config->getUser();
149  case "host":
150  return $this->config->getHost();
151  case "port":
152  return (string) $this->config->getPort();
153  case "pass":
154  $pw = $this->config->getPassword();
155  return $pw ? $pw->toString() : "";
156  case "name":
157  return $this->config->getDatabase();
158  case "type":
159  return $this->config->getType();
160  default:
161  throw new \LogicException(
162  "Cannot provide variable '$a_var_name'"
163  );
164  }
165  }
166 
167  public function __construct(\ilDatabaseSetupConfig $config)
168  {
169  $this->config = $config;
170  }
171  public function read(): bool
172  {
173  throw new \LogicException("Just a mock here...");
174  }
175  public function parse(): bool
176  {
177  throw new \LogicException("Just a mock here...");
178  }
179  public function fixIniFile(): void
180  {
181  throw new \LogicException("Just a mock here...");
182  }
183  public function write(): bool
184  {
185  throw new \LogicException("Just a mock here...");
186  }
187  public function show(): string
188  {
189  throw new \LogicException("Just a mock here...");
190  }
191  public function getGroupCount(): int
192  {
193  throw new \LogicException("Just a mock here...");
194  }
195  public function readGroups(): array
196  {
197  throw new \LogicException("Just a mock here...");
198  }
199  public function groupExists(string $a_group_name): bool
200  {
201  throw new \LogicException("Just a mock here...");
202  }
203  public function readGroup(string $a_group_name): array
204  {
205  throw new \LogicException("Just a mock here...");
206  }
207  public function addGroup(string $a_group_name): bool
208  {
209  throw new \LogicException("Just a mock here...");
210  }
211  public function removeGroup(string $a_group_name): bool
212  {
213  throw new \LogicException("Just a mock here...");
214  }
215  public function variableExists(string $a_group, string $a_var_name): bool
216  {
217  throw new \LogicException("Just a mock here...");
218  }
219  public function setVariable(string $a_group_name, string $a_var_name, string $a_var_value): bool
220  {
221  throw new \LogicException("Just a mock here...");
222  }
223  public function error(string $a_errmsg): bool
224  {
225  throw new \LogicException("Just a mock here...");
226  }
227  public function getError(): string
228  {
229  throw new \LogicException("Just a mock here...");
230  }
231  };
232  }
233 }
toMockIniFile()
Adapter to current database-handling via a mock of .
A password is used as part of credentials for authentication.
Definition: Password.php:16
static getAvailableCollations()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $type, string $host, string $database, string $user, Password $password=null, bool $create_database=true, string $collation=null, int $port=null, string $path_to_db_dump=null)
static getInstallableTypes()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...