Skip to content

Commit 4cae8d8

Browse files
committed
Update TraitConfiguration.php
YAML support
1 parent aebb2d3 commit 4cae8d8

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/TraitConfiguration.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,25 @@ protected function getModuleNamespace() : string
247247
* Get database access.
248248
*
249249
* @access protected
250+
* @param string $type
250251
* @return array
251252
*/
252-
protected function getDbAccess() : array
253+
protected function getDbAccess(string $type = 'default') : array
253254
{
254-
$access = $this->parseIni($this->getDatabaseFile(), true);
255-
Validator::checkDatabaseConfig($access);
256-
return $this->mergeArray([
257-
'host' => 'localhost',
258-
'port' => 3306,
259-
'name' => '',
260-
'user' => '',
261-
'pswd' => '',
262-
'charset' => 'utf8',
263-
'collate' => 'utf8_general_ci'
264-
], $access['default']);
255+
$file = $this->getDbFile();
256+
$extension = $this->getFileExtension($file);
257+
$data = [];
258+
259+
if ( $extension == 'yaml' ) {
260+
$data = $this->parseYaml($file, $type) ?: [];
261+
262+
} elseif ( $extension == 'ini' ) {
263+
$data = $this->parseIni($file, true);
264+
$data = $data[$type] ?? [];
265+
}
266+
267+
Validator::checkDatabaseConfig($data, $type);
268+
return $data;
265269
}
266270

267271
/**
@@ -272,12 +276,7 @@ protected function getDbAccess() : array
272276
*/
273277
protected function getDbRootAccess() : array
274278
{
275-
$access = $this->parseIni($this->getDatabaseFile(), true);
276-
Validator::checkDatabaseConfig($access);
277-
return $this->mergeArray([
278-
'user' => '',
279-
'pswd' => ''
280-
], $access['root']);
279+
return $this->getDbAccess('root');
281280
}
282281

283282
/**
@@ -580,12 +579,12 @@ protected function getRoutesFile() : string
580579
}
581580

582581
/**
583-
* Get database file path.
582+
* Get database config file.
584583
*
585584
* @access protected
586585
* @return string
587586
*/
588-
protected function getDatabaseFile() : string
587+
protected function getDbFile() : string
589588
{
590589
$path = "{$this->getRoot()}/{$this->global->path->db}";
591590
return $this->formatPath($path, true);

0 commit comments

Comments
 (0)