54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
namespace Hanyuu;
|
|
|
|
use Index\Autoloader;
|
|
use Index\Environment;
|
|
use Index\Data\DbTools;
|
|
use Hanyuu\Config\IConfig;
|
|
use Hanyuu\Config\ArrayConfig;
|
|
|
|
define('HAU_STARTUP', microtime(true));
|
|
define('HAU_ROOT', __DIR__);
|
|
define('HAU_CLI', PHP_SAPI === 'cli');
|
|
define('HAU_DEBUG', is_file(HAU_ROOT . '/.debug'));
|
|
define('HAU_DIR_PUBLIC', HAU_ROOT . '/public');
|
|
define('HAU_DIR_SOURCE', HAU_ROOT . '/src');
|
|
define('HAU_DIR_LIBRARIES', HAU_ROOT . '/lib');
|
|
define('HAU_DIR_CONFIG', HAU_ROOT . '/config');
|
|
define('HAU_DIR_MIGRATIONS', HAU_ROOT . '/database');
|
|
define('HAU_DIR_TEMPLATES', HAU_ROOT . '/templates');
|
|
|
|
define('HAU_NDX_PATH', HAU_DIR_LIBRARIES . '/index');
|
|
define('HAU_NDX_PATH_DEV', HAU_DIR_LIBRARIES . '/index-dev');
|
|
|
|
require_once (HAU_DEBUG && is_dir(HAU_NDX_PATH_DEV) ? HAU_NDX_PATH_DEV : HAU_NDX_PATH) . '/index.php';
|
|
|
|
Autoloader::addNamespace(__NAMESPACE__, HAU_DIR_SOURCE);
|
|
Environment::setDebug(HAU_DEBUG);
|
|
|
|
mb_internal_encoding('utf-8');
|
|
date_default_timezone_set('utc');
|
|
set_include_path(get_include_path() . PATH_SEPARATOR . HAU_ROOT);
|
|
|
|
set_exception_handler(function(\Throwable $ex) {
|
|
if(HAU_CLI)
|
|
die((string)$ex);
|
|
|
|
http_response_code(500);
|
|
ob_clean();
|
|
|
|
if(HAU_DEBUG) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
die((string)$ex);
|
|
}
|
|
|
|
header('Content-Type: text/html; charset-utf-8');
|
|
die('<h2>Hanyuu is sad.</h2>');
|
|
});
|
|
|
|
$cfg = ArrayConfig::open(HAU_DIR_CONFIG . '/config.ini');
|
|
|
|
$dbc = DbTools::create($cfg->getValue('database:dsn', IConfig::T_STR, 'null'));
|
|
$dbc->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';');
|
|
|
|
$hau = new HanyuuContext($cfg, $dbc);
|