/** * Main init function. When using _PHP, the function: _Config::init() * should be called at the top of EVERY controller or php script. This is required if the full framework * is being used and not just the stand-alone libraries * * @param string $environmentOverride (optional) * @return bool | TRUE on success / FALSE on failure */ public static function init($environmentOverride = FALSE) { // Prevent init() being called more than once if (self::$isInitialized) { return FALSE; } self::setProjectDirectoryConstants(); // Include other required config files require_once _PROJECT_ROOT_PATH . 'config/version.php'; require_once _PROJECT_ROOT_PATH . 'config/environments.php'; if ($environmentOverride === FALSE) { self::setEnvironment(); } else { self::setEnvironment($environmentOverride); } self::setIsSSL(); $rc = @session_start(); if ($rc !== TRUE) { _\_Log::warn('Unable to initialize session'); } self::$isInitialized = TRUE; // Bootstrap require_once _PROJECT_ROOT_PATH . 'config/bootstrap.php'; return TRUE; }
$router = new Router($_GET['url']); $router->get('', function () use($auth, $config, $session) { if (!$auth->isConnected()) { header("Location: " . ROOT . "login"); die; } else { require "template/index.php"; } }); /* AUTH */ $router->get('logout', function () use($auth, $config, $session) { $auth->logout(); header("Location: " . ROOT . "login"); }); $router->get('login', function () use($auth, $config, $session) { if (!$config->isInitialized()) { header("Location: " . ROOT . "install"); } if ($auth->isConnected()) { header("Location: " . ROOT); } else { require "template/login.php"; } }); $router->post('login', function () use($auth, $config, $session) { if ($auth->login($_POST["email"], $_POST["pass"])) { $session->setFlash("info", "Connexion réussie"); header("Location: " . ROOT); } else { $session->setFlash("info", "Identifiants incorrects"); }