Cleaner boot script.

parent 667696f2
......@@ -2,13 +2,20 @@
use RedBeanPHP\R;
require_once __DIR__ . '/vendor/autoload.php';
function c($param = null, $default = null)
/**
* Helper to get config values.
*
* @param null|string $param
* @param null|mixed $default
*
* @return mixed|null
*/
function c(string $param = null, $default = null)
{
static $config;
if ($config === null) {
$config = require __DIR__ . '/config.php';
is_array($config) || die('Invalid config format.');
}
if ($param === null) {
......@@ -24,7 +31,19 @@ function c($param = null, $default = null)
define('PODUPTIME', microtime(true));
require_once __DIR__ . '/vendor/autoload.php';
// Set up global DB connection.
R::setup('pgsql:host=' . c('pghost') . ';dbname=' . c('pgdb'), c('pguser'), c('pgpass'), true);
R::setup(
sprintf(
'pgsql:host=%s;port=%d;dbname=%s',
c('pghost'),
c('pgport', 5432),
c('pgdb')
),
c('pguser'),
c('pgpass'),
true
);
R::testConnection() || die('Error in DB connection');
R::usePartialBeans(true);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment