<?php

if (strpos($_SERVER['REQUEST_URI'], '/api/quick/') === 0) {
    define('NO_FRAMEWORK_API_BASE_URL', '/api/quick');

    require_once dirname(__DIR__, 2) . '/no-framework-api/api.php';
    return;
}

//ini_set('display_errors',1);
//ini_set('display_startup_errors',1);
//error_reporting(-1);

require_once dirname(__DIR__, 2) . '/config/Project.def.php';

// Define touch
define('TOUCH', true);

require_once VENDOR_PATH . '/autoload.php';
require_once 'viper/config/ViperConfig.php';

// Sentry integration
$sentryConfigOptions = [
    'environment' => (string)\ViperConfig::get('Application')->attributes()->env,
];

foreach (\ViperConfig::get('sentry') as $oneKey => $oneValue) {
    switch ($oneValue->attributes()->type) {
        case 'int':
        case 'integer':
            $sentryConfigOptions[$oneKey] = (int)$oneValue;
            break;
        case 'float':
            $sentryConfigOptions[$oneKey] = (float)$oneValue;
            break;
        case 'bool':
        case 'boolean':
            $sentryConfigOptions[$oneKey] = filter_var($oneValue, FILTER_VALIDATE_BOOLEAN);
            break;
        case 'str':
        case 'string':
        default:
            $sentryConfigOptions[$oneKey] = (string)$oneValue;
            break;
    }
}

\Sentry\init($sentryConfigOptions);

$app = ViperConfig::get('Application');
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (string)$app['env']);

// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, array('module' => 'touch'));
$application->setBootstrap(APPLICATION_PATH . '/Bootstrap.php');

try {
    $application->bootstrap()->run();
} catch (\Exception $exception) {
    header('HTTP/1.1 500 Internal Server Error');
    \Logger::getLogger()->error('[BOOTSTRAP ERROR: ] ' . $exception->getMessage());
}
