boot.php 922 Bytes
Newer Older
1 2 3 4
<?php

use RedBeanPHP\R;

noplanman's avatar
noplanman committed
5 6 7 8 9 10 11 12 13
/**
 * Helper to get config values.
 *
 * @param null|string $param
 * @param null|mixed  $default
 *
 * @return mixed|null
 */
function c(string $param = null, $default = null)
14 15 16 17
{
    static $config;
    if ($config === null) {
        $config = require __DIR__ . '/config.php';
noplanman's avatar
noplanman committed
18
        is_array($config) || die('Invalid config format.');
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
    }

    if ($param === null) {
        return $config;
    }

    if (array_key_exists($param, $config)) {
        return $config[$param];
    }

    return $default;
}

define('PODUPTIME', microtime(true));

noplanman's avatar
noplanman committed
34 35
require_once __DIR__ . '/vendor/autoload.php';

36
// Set up global DB connection.
noplanman's avatar
noplanman committed
37 38 39 40 41 42 43 44 45 46 47
R::setup(
    sprintf(
        'pgsql:host=%s;port=%d;dbname=%s',
        c('pghost'),
        c('pgport', 5432),
        c('pgdb')
    ),
    c('pguser'),
    c('pgpass'),
    true
);
48 49
R::testConnection() || die('Error in DB connection');
R::usePartialBeans(true);