1 | <?php |
||
27 | class DbSettings implements ArrayAccess, IteratorAggregate |
||
28 | { |
||
29 | /** |
||
30 | * @var string|null known field members |
||
31 | */ |
||
32 | private $tablePrefix, $host, $port, $unixSocket, $dbName, $username, $password; |
||
|
|||
33 | |||
34 | /** |
||
35 | * @var array field array |
||
36 | */ |
||
37 | private $config; |
||
38 | |||
39 | /** |
||
40 | * @param string $file path to app/etc/local.xml |
||
41 | */ |
||
42 | public function __construct($file) |
||
46 | |||
47 | /** |
||
48 | * @param string $file path to app/etc/local.xml |
||
49 | * |
||
50 | * @throws InvalidArgumentException if the file is invalid |
||
51 | */ |
||
52 | public function setFile($file) |
||
81 | |||
82 | /** |
||
83 | * helper method to parse config file segment related to the database settings |
||
84 | * |
||
85 | * @param SimpleXMLElement $resources |
||
86 | */ |
||
87 | private function parseResources(SimpleXMLElement $resources) |
||
128 | |||
129 | /** |
||
130 | * Get Mysql PDO DSN |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public function getDsn() |
||
158 | |||
159 | /** |
||
160 | * Connects to the database without initializing magento |
||
161 | * |
||
162 | * @throws RuntimeException if pdo_mysql extension is not installed |
||
163 | * @return PDO |
||
164 | */ |
||
165 | public function getConnection() |
||
197 | |||
198 | public function getMysqlClientToolConnectionString() |
||
219 | |||
220 | /** |
||
221 | * Mysql quoting of an identifier |
||
222 | * |
||
223 | * @param string $identifier UTF-8 encoded |
||
224 | * |
||
225 | * @return string quoted identifier |
||
226 | */ |
||
227 | private function quoteIdentifier($identifier) |
||
244 | |||
245 | /** |
||
246 | * @return bool |
||
247 | */ |
||
248 | public function isSocketConnect() |
||
252 | |||
253 | /** |
||
254 | * @return string table prefix, null if not in the settings (no or empty prefix) |
||
255 | */ |
||
256 | public function getTablePrefix() |
||
260 | |||
261 | /** |
||
262 | * @return string hostname, null if there is no hostname setup (e.g. unix_socket) |
||
263 | */ |
||
264 | public function getHost() |
||
268 | |||
269 | /** |
||
270 | * @return string port, null if not setup |
||
271 | */ |
||
272 | public function getPort() |
||
276 | |||
277 | /** |
||
278 | * @return string username |
||
279 | */ |
||
280 | public function getUsername() |
||
284 | |||
285 | /** |
||
286 | * @return string password |
||
287 | */ |
||
288 | public function getPassword() |
||
292 | |||
293 | /** |
||
294 | * @return string unix socket, null if not in use |
||
295 | */ |
||
296 | public function getUnixSocket() |
||
300 | |||
301 | /** |
||
302 | * content of previous $dbSettings field of the DatabaseHelper |
||
303 | * |
||
304 | * @return array |
||
305 | */ |
||
306 | public function getConfig() |
||
310 | |||
311 | /** |
||
312 | * @return string of the database identifier, null if not in use |
||
313 | */ |
||
314 | public function getDatabaseName() |
||
318 | |||
319 | /* |
||
320 | * ArrayAccess interface |
||
321 | */ |
||
322 | |||
323 | /** |
||
324 | * @return boolean true on success or false on failure. |
||
325 | */ |
||
326 | public function offsetExists($offset) |
||
330 | |||
331 | /** |
||
332 | * @return mixed Can return all value types. |
||
333 | */ |
||
334 | public function offsetGet($offset) |
||
342 | |||
343 | /** |
||
344 | * @param mixed $offset |
||
345 | * @param mixed $value |
||
346 | * |
||
347 | * @throws BadMethodCallException |
||
348 | */ |
||
349 | public function offsetSet($offset, $value) |
||
353 | |||
354 | /** |
||
355 | * @param mixed $offset |
||
356 | * |
||
357 | * @throws BadMethodCallException |
||
358 | */ |
||
359 | public function offsetUnset($offset) |
||
363 | |||
364 | /* |
||
365 | * IteratorAggregate |
||
366 | */ |
||
367 | |||
368 | /** |
||
369 | * @return ArrayIterator |
||
370 | */ |
||
371 | public function getIterator() |
||
375 | } |
||
376 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.