56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
const PRODUCTION = false;
|
|
const DEBUG = true;
|
|
|
|
if(DEBUG){
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
}
|
|
|
|
|
|
// Composer autoload
|
|
require_once 'vendor/autoload.php';
|
|
|
|
|
|
// Application and Models autoload
|
|
spl_autoload_register(function ($class_name) {
|
|
if(file_exists(__DIR__."/application/".$class_name.'.php')){
|
|
include __DIR__."/application/".$class_name.'.php';
|
|
}
|
|
elseif(file_exists(__DIR__."/models/".$class_name.'.php')) {
|
|
include __DIR__."/models/".$class_name.'.php';
|
|
}
|
|
});
|
|
|
|
|
|
// Define Twig
|
|
$twigSettings = PRODUCTION?['cache' => __dir__.'/tmp/']:[];
|
|
|
|
$loader = new Twig\Loader\FilesystemLoader(__dir__ . '/templates/'.Config::get('system', 'template', 'default')."/");
|
|
$twig = new Twig\Environment($loader, $twigSettings);
|
|
|
|
|
|
class Config {
|
|
private static $instance = null;
|
|
private $config;
|
|
|
|
private function __construct($file = 'config/config.ini'){
|
|
$this->config = parse_ini_file($file, true);
|
|
}
|
|
|
|
public static function get(string $category, string $config, $default = false){
|
|
// Singleton method to avoid reading the same file (too) many times
|
|
if (self::$instance == null){
|
|
self::$instance = new Config();
|
|
}
|
|
|
|
$conf = self::$instance;
|
|
|
|
if(!empty($conf->config[$category]) && !empty($conf->config[$category][$config])){
|
|
return $conf->config[$category][$config];
|
|
}
|
|
return $default;
|
|
}
|
|
} |