uiharu/uiharu.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2022-07-14 20:42:37 +00:00
<?php
namespace Uiharu;
use Index\Autoloader;
use Index\Environment;
use Index\Data\ConnectionFailedException;
use Index\Data\DbTools;
define('UIH_STARTUP', microtime(true));
define('UIH_ROOT', __DIR__);
define('UIH_DEBUG', is_file(UIH_ROOT . '/.debug'));
define('UIH_PUBLIC', UIH_ROOT . '/public');
define('UIH_SOURCE', UIH_ROOT . '/src');
define('UIH_LIBRARY', UIH_ROOT . '/lib');
define('UIH_VERSION', '20230609');
2022-07-14 20:42:37 +00:00
define('UIH_NDX_PATH', UIH_LIBRARY . '/index');
define('UIH_NDX_PATH_DEV', UIH_LIBRARY . '/index-dev');
require_once (UIH_DEBUG && is_dir(UIH_NDX_PATH_DEV) ? UIH_NDX_PATH_DEV : UIH_NDX_PATH) . '/index.php';
2022-07-14 20:42:37 +00:00
Autoloader::addNamespace('Masterminds', UIH_LIBRARY . '/html5-php/src');
2022-07-14 20:42:37 +00:00
Autoloader::addNamespace(__NAMESPACE__, UIH_SOURCE);
Environment::setDebug(UIH_DEBUG);
mb_internal_encoding('utf-8');
date_default_timezone_set('utc');
$configPath = UIH_ROOT . '/config.ini';
if(!is_file($configPath))
die('Uiharu configuration is missing.');
Config::load($configPath);
if(!Config::has('Database', 'dsn'))
die('Uiharu database is not configured.');
try {
$db = DbTools::create(Config::get('Database', 'dsn'));
} catch(ConnectionFailedException $ex) {
echo '<h3>Unable to connect to database</h3>';
die($ex->getMessage());
}
$ctx = new UihContext($db);