-
Notifications
You must be signed in to change notification settings - Fork 123
/
config.php
executable file
·44 lines (37 loc) · 1.47 KB
/
config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
define('DIR_ROOT', dirname(__FILE__));
define('ENVIRONMENT_FILE', DIR_ROOT . '/.environment');
define('DRIVER_DIR', DIR_ROOT . '/driver/');
define('TEMPLATE_DIR', DIR_ROOT . '/template/');
if(isset($_ENV['DATABASE_DRIVER']) && isset($_ENV['DATABASE_HOST']) && isset($_ENV['DATABASE_HOST_SECONDARY'])){
$params = $_ENV;
}else{
if (!file_exists(ENVIRONMENT_FILE)) die('File "' . ENVIRONMENT_FILE . '" not exist. Please create file.');
$params = parse_ini_file(ENVIRONMENT_FILE, false, INI_SCANNER_RAW);
}
$requiredParams = array(
'DATABASE_DRIVER',
'DATABASE_ENCODING',
'SAMPLE_DATA_LENGTH',
'DATABASE_HOST',
'DATABASE_PORT',
'DATABASE_NAME',
'DATABASE_USER',
'DATABASE_PASSWORD',
'DATABASE_DESCRIPTION',
'DATABASE_HOST_SECONDARY',
'DATABASE_PORT_SECONDARY',
'DATABASE_NAME_SECONDARY',
'DATABASE_USER_SECONDARY',
'DATABASE_PASSWORD_SECONDARY',
'DATABASE_DESCRIPTION_SECONDARY',
);
array_map(function ($name) use ($params) {
if (!isset($params[$name])) {
die('Param ' . $name . ' not set in file ' . ENVIRONMENT_FILE);
}else{
define($name, $params[$name]);
}
}, $requiredParams);
define('FIRST_DSN', DATABASE_DRIVER.'://'.DATABASE_USER.':'.DATABASE_PASSWORD.'@'.DATABASE_HOST.':'.DATABASE_PORT.'/'.DATABASE_NAME);
define('SECOND_DSN', DATABASE_DRIVER.'://'.DATABASE_USER_SECONDARY.':'.DATABASE_PASSWORD_SECONDARY.'@'.DATABASE_HOST_SECONDARY.':'.DATABASE_PORT_SECONDARY.'/'.DATABASE_NAME_SECONDARY);