ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDatabaseSetupConfig.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
7
9{
10 const DEFAULT_COLLATION = "utf8_general_ci";
11 const DEFAULT_PATH_TO_DB_DUMP = "./setup/sql/ilias3.sql";
12
16 protected $type;
17
21 protected $host;
22
26 protected $port;
27
31 protected $database;
32
37
41 protected $collation;
42
46 protected $user;
47
51 protected $password;
52
57
58 public function __construct(
59 $type,
60 string $host,
61 string $database,
62 string $user,
63 Password $password = null,
64 bool $create_database = true,
65 string $collation = null,
66 string $port = null,
67 string $path_to_db_dump = null
68 ) {
69 if (!in_array($type, \ilDBConstants::getInstallableTypes())) {
70 throw new \InvalidArgumentException(
71 "Unknown database type: $type"
72 );
73 }
75 throw new \InvalidArgumentException(
76 "Unknown collation: $collation"
77 );
78 }
79 $this->type = trim($type);
80 $this->host = trim($host);
81 $this->database = trim($database);
82 $this->user = trim($user);
83 $this->password = $password;
84 $this->create_database = trim($create_database);
85 $this->collation = $collation ? trim($collation) : self::DEFAULT_COLLATION;
86 $this->port = $port;
87 $this->path_to_db_dump = $path_to_db_dump ?? self::DEFAULT_PATH_TO_DB_DUMP;
88 }
89
90 public function getType()
91 {
92 return $this->type;
93 }
94
95 public function getHost() : string
96 {
97 return $this->host;
98 }
99
100 public function getPort() : ?string
101 {
102 return $this->port;
103 }
104
105 public function getDatabase() : string
106 {
107 return $this->database;
108 }
109
110 public function getCreateDatabase() : bool
111 {
113 }
114
115 public function getCollation() : string
116 {
117 return $this->collation;
118 }
119
120 public function getUser() : string
121 {
122 return $this->user;
123 }
124
125 public function getPassword() : ?Password
126 {
127 return $this->password;
128 }
129
130 public function getPathToDBDump() : string
131 {
133 }
134
138 public function toMockIniFile() : \ilIniFile
139 {
140 return new class($this) extends \ilIniFile {
148 public function readVariable($a_group, $a_var_name)
149 {
150 if ($a_group !== "db") {
151 throw new \LogicException(
152 "Can only access db-config via this mock."
153 );
154 }
155 switch ($a_var_name) {
156 case "user":
157 return $this->config->getUser();
158 case "host":
159 return $this->config->getHost();
160 case "port":
161 return $this->config->getPort();
162 case "pass":
163 $pw = $this->config->getPassword();
164 return $pw ? $pw->toString() : null;
165 case "name":
166 return $this->config->getDatabase();
167 case "type":
168 return $this->config->getType();
169 default:
170 throw new \LogicException(
171 "Cannot provide variable '$a_var_name'"
172 );
173 }
174 }
176 {
177 $this->config = $config;
178 }
179 public function read()
180 {
181 throw new \LogicException("Just a mock here...");
182 }
183 public function parse()
184 {
185 throw new \LogicException("Just a mock here...");
186 }
187 public function fixIniFile()
188 {
189 throw new \LogicException("Just a mock here...");
190 }
191 public function write()
192 {
193 throw new \LogicException("Just a mock here...");
194 }
195 public function show()
196 {
197 throw new \LogicException("Just a mock here...");
198 }
199 public function getGroupCount()
200 {
201 throw new \LogicException("Just a mock here...");
202 }
203 public function readGroups()
204 {
205 throw new \LogicException("Just a mock here...");
206 }
207 public function groupExists($a_group_name)
208 {
209 throw new \LogicException("Just a mock here...");
210 }
211 public function readGroup($a_group_name)
212 {
213 throw new \LogicException("Just a mock here...");
214 }
215 public function addGroup($a_group_name)
216 {
217 throw new \LogicException("Just a mock here...");
218 }
219 public function removeGroup($a_group_name)
220 {
221 throw new \LogicException("Just a mock here...");
222 }
223 public function variableExists($a_group, $a_var_name)
224 {
225 throw new \LogicException("Just a mock here...");
226 }
227 public function setVariable($a_group_name, $a_var_name, $a_var_value)
228 {
229 throw new \LogicException("Just a mock here...");
230 }
231 public function error($a_errmsg)
232 {
233 throw new \LogicException("Just a mock here...");
234 }
235 public function getError()
236 {
237 throw new \LogicException("Just a mock here...");
238 }
239 };
240 }
241}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
A password is used as part of credentials for authentication.
Definition: Password.php:14
getError()
returns error @access public
show()
returns the content of IniFile @access public
readGroups()
returns an array with the names of all the groups @access public
variableExists($a_group, $a_var_name)
returns if a variable exists or not @access public
getGroupCount()
returns number of groups @access public
removeGroup($a_group_name)
removes a group @access public
readGroup($a_group_name)
returns an associative array of the variables in one group @access public
addGroup($a_group_name)
adds a new group @access public
readVariable($a_group, $a_var_name)
reads a single variable from a group @access public
setVariable($a_group_name, $a_var_name, $a_var_value)
sets a variable in a group @access public
groupExists($a_group_name)
checks if a group exists @access public
error($a_errmsg)
set error message @access public
static getAvailableCollations()
static getInstallableTypes()
toMockIniFile()
Adapter to current database-handling via a mock of \ilIniFile.
__construct( $type, string $host, string $database, string $user, Password $password=null, bool $create_database=true, string $collation=null, string $port=null, string $path_to_db_dump=null)
INIFile Parser.
A configuration for the setup.
Definition: Config.php:11
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...