<?php
namespace Mince;

use Index\Config\Fs\FsConfig;
use Index\Db\DbBackends;

define('MCR_STARTUP', microtime(true));
define('MCR_ROOT', __DIR__);
define('MCR_DEBUG', is_file(MCR_ROOT . '/.debug'));
define('MCR_DIR_SRC', MCR_ROOT . '/src');
define('MCR_DIR_PUB', MCR_ROOT . '/public');
define('MCR_DIR_PRV', MCR_ROOT . '/private');
define('MCR_DIR_MIG', MCR_ROOT . '/database');
define('MCR_DIR_TPL', MCR_ROOT . '/templates');

require_once MCR_ROOT . '/vendor/autoload.php';

error_reporting(MCR_DEBUG ? -1 : 0);
mb_internal_encoding('UTF-8');
date_default_timezone_set('GMT');

$cfg = FsConfig::fromFile(MCR_ROOT . '/mince.cfg');

if($cfg->hasValues('sentry:dsn'))
    (function($cfg) {
        \Sentry\init([
            'dsn' => $cfg->getString('dsn'),
            'traces_sample_rate' => $cfg->getFloat('tracesRate', 0.2),
            'profiles_sample_rate' => $cfg->getFloat('profilesRate', 0.2),
        ]);

        set_exception_handler(function(\Throwable $ex) {
            \Sentry\captureException($ex);
        });
    })($cfg->scopeTo('sentry'));

$mince = new MinceContext($cfg);