1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_pedigree; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_mapper\Interfaces\IDriverSources; |
7
|
|
|
use kalanis\kw_mapper\MapperException; |
8
|
|
|
use kalanis\kw_mapper\Storage\Database; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Config |
13
|
|
|
* @package kalanis\kw_pedigree |
14
|
|
|
* Default configuration for testing DB in kw_pedigree |
15
|
|
|
* You can call your own implementation and settings in bootstrap |
16
|
|
|
* This is mainly example of configuration, but you can use it |
17
|
|
|
*/ |
18
|
|
|
class Config |
19
|
|
|
{ |
20
|
2 |
|
public static function init(string $sourceName = 'pedigree'): void |
21
|
|
|
{ |
22
|
|
|
try { // try if this config exists |
23
|
2 |
|
Database\ConfigStorage::getInstance()->getConfig($sourceName); |
24
|
2 |
|
} catch (MapperException $ex) { // if not use our own - with possibility to set it from environment variables |
25
|
2 |
|
$type = getenv('KW_PEDIGREE_DB_TYPE'); |
26
|
2 |
|
$host = getenv('KW_PEDIGREE_DB_HOST'); |
27
|
2 |
|
$port = getenv('KW_PEDIGREE_DB_PORT'); |
28
|
2 |
|
$user = getenv('KW_PEDIGREE_DB_USER'); |
29
|
2 |
|
$pass = getenv('KW_PEDIGREE_DB_PASS'); |
30
|
2 |
|
$db = getenv('KW_PEDIGREE_DB_NAME'); |
31
|
2 |
|
Database\ConfigStorage::getInstance()->addConfig( |
32
|
2 |
|
Database\Config::init()->setTarget( |
33
|
2 |
|
((false !== $type) && !is_array($type)) ? strval($type) : IDriverSources::TYPE_PDO_MYSQL, |
34
|
|
|
$sourceName, |
35
|
2 |
|
((false !== $host) && !is_array($host)) ? strval($host) : 'kwcms-mariadb', |
36
|
2 |
|
((false !== $port) && !is_array($port)) ? intval($port) : 3306, |
37
|
2 |
|
((false !== $user) && !is_array($user)) ? strval($user) : 'root', |
38
|
2 |
|
((false !== $pass) && !is_array($pass)) ? strval($pass) : '951357456852', |
39
|
2 |
|
((false !== $db) && !is_array($db)) ? strval($db) : 'kwcms' |
40
|
|
|
) |
41
|
|
|
); |
42
|
|
|
} |
43
|
2 |
|
} |
44
|
|
|
} |
45
|
|
|
|