<?php
/**
 * Boot the app
 */

// Set environment variables
function setEnvVars() {
    if (!file_exists('.env')) return;

    foreach (file('.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
        if (strpos($line, '#') === 0) continue;

        list($label, $value) = explode('=', $line, 2);
        $label = trim($label);
        $value = trim($value);
        if (strtolower($value) === 'true') {
            $value = true;
        } elseif (strtolower($value) === 'false') {
            $value = false;
        } elseif (is_numeric($value)) {
            $value = (int) $value;
        }
        define($label, $value);
    }
}

setEnvVars();

// Display all errors
error_reporting(E_ALL);

// Set cache control
// header('Cache-Control: no cache');
header('Cache-Control: public');

// Don't send expired header to client
// session_cache_limiter('private_no_expire');

// Set constants
define('ROOT_DIR', getcwd());
define('UPLOAD_DIR', getcwd() . '/projects/');

// Start the session
session_start();

// If the session is empty, redirect user back to index.
$currentFile = basename($_SERVER['PHP_SELF']);
if ($currentFile !== 'index.php' && !isset($_SESSION['uuid'])) {
    header('Location: index.php');
    exit;
}
