-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.php
59 lines (44 loc) · 1.17 KB
/
boot.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* OpenTHC Directory Bootstrap
*
* SPDX-License-Identifier: GPL-3.0-only
*/
define('APP_ROOT', __DIR__);
error_reporting(E_ALL & ~ E_NOTICE);
openlog('openthc-dir', LOG_ODELAY|LOG_PID, LOG_LOCAL0);
require_once(APP_ROOT . '/vendor/autoload.php');
if ( ! \OpenTHC\Config::init(APP_ROOT) ) {
_exit_html_fail('<h1>Invalid Application Configuration [ALB-035]</h1>', 500);
}
define('OPENTHC_SERVICE_ID', \OpenTHC\Config::get('openthc/dir/id'));
define('OPENTHC_SERVICE_ORIGIN', \OpenTHC\Config::get('openthc/dir/origin'));
function _acl()
{
return true;
}
/**
* Database Connection Helper
*/
function _dbc($conn='main')
{
static $dbc_list = [];
if ( ! empty($dbc_list[$conn])) {
return $dbc_list[$conn];
}
$dbc = null;
switch ($conn) {
case 'auth':
case 'main':
$cfg = \OpenTHC\Config::get(sprintf('database/%s', $conn));
$dsn = sprintf('pgsql:application_name=openthc-dir;host=%s;dbname=%s', $cfg['hostname'], $cfg['database']);
$dbc = new \Edoceo\Radix\DB\SQL($dsn, $cfg['username'], $cfg['password']);
break;
// default:
// $dbc = new \Edoceo\Radix\DB\SQL($conn);
}
if ( ! empty($dbc)) {
$dbc_list[$conn] = $dbc;
}
return $dbc;
}