<?php if (!defined('_PROJECT_ROOT_PATH')) { define('_PROJECT_ROOT_PATH', realpath(dirname(__FILE__) . '/../../') . '/'); } require_once _PROJECT_ROOT_PATH . 'vendor/autoload.php'; require_once _PROJECT_ROOT_PATH . 'config/Config.php'; Config::init(); $_action = isset($_GET) && isset($_GET['action']) ? $_GET['action'] : ''; // Use _Libs _\_Log::debug('Action called on default controller: ' . $_action); switch ($_action) { // http://localhost/exception case 'exception': throw new Exception('test exception'); break; // http://localhost/ // http://localhost/index // http://localhost/ // http://localhost/index case 'index': include _VIEWS . 'header.php'; include _VIEWS . 'index.php'; include _VIEWS . 'footer.php'; break; case 'underscore_libs': include _VIEWS . 'header.php'; include _VIEWS . 'underscore_libs.php'; include _VIEWS . 'footer.php'; break; case 'underscore_php':
/** * Sets the environment variable and include() for environment config file * * @param string $environmentOverride | When set, will override the environment instead of setting it based on $_SERVER['SERVER_NAME'] * @return boolean | TRUE on success / FALSE on failure */ private static function setEnvironment($environmentOverride = FALSE) { if ($environmentOverride !== false) { $env = $environmentOverride; $filename = _PROJECT_ROOT_PATH . 'env/' . $environmentOverride . '.php'; if (!file_exists($filename)) { _\_Log::fatal('*** Environment Override ' . $environmentOverride . ' is invalid. ***'); return FALSE; } require_once $filename; } else { if (!isset($GLOBALS['environments'])) { throw new _Exception('*** Environment not set. Check /env/environments.php ***'); } self::$environments = $GLOBALS['environments']; $defaultConfig = isset($GLOBALS['environments']['_DEFAULT_']) ? $GLOBALS['environments']['_DEFAULT_'] : FALSE; // Get server name if (isset($_SERVER) && isset($_SERVER['SERVER_NAME'])) { $serverName = $_SERVER['SERVER_NAME']; if (isset(self::$environments[$serverName])) { $env = self::$environments[$serverName]; } elseif ($defaultConfig !== FALSE) { _\_Log::warn('*** SERVER_NAME (' . $serverName . ') does not match any defined environments. Using default. ***'); $env = $defaultConfig; } else { _\_Log::fatal('*** SERVER_NAME (' . $serverName . ') does not match any defined environments and no default was set. ***'); return FALSE; } } elseif ($defaultConfig !== FALSE) { _\_Log::warn('*** SERVER_NAME is not set. Please set this variable in apache or use the $environmentOverride option on _Config::init(). Using default configuration.'); $env = $defaultConfig; } $filename = _PROJECT_ROOT_PATH . 'env/' . $env . '.php'; } self::$env = $env; if (!file_exists($filename)) { _\_Log::fatal('*** Environment file does not exist: ' . $filename . ' ***'); return FALSE; } $filename = _PROJECT_ROOT_PATH . 'env/' . $env . '.php'; require_once $filename; return TRUE; }