/** * Fetches the Application Main Config from file or APC. * * @return type */ public function getApplicationConfig() { $config = []; $apcAppKey = APPLICATION_NAME . '.config'; // load config from APC if (APC && apc_exists($apcAppKey)) { $config = apc_fetch($apcAppKey); } else { // load config from file $config = \Koch\Config\Adapter\INI::read(APPLICATION_PATH . 'Configuration/' . APPLICATION_NAME . '.php'); // set to APC if (APC) { apc_add($apcAppKey, $config); } } unset($apcAppKey); // merge config with a staging configuration if (isset($config['config']['staging']) && (bool) $config['config']['staging']) { $config = \Koch\Config\Staging::overloadWithStagingConfig($config); } return $config; }
/** * testMethod_getFilename() */ public function testMethod_getFilename() { $expected_filename = ROOT_CONFIG . 'staging/' . 'development.php'; $filename = Staging::getFilename(); $this->assertEqual($filename, $expected_filename); }
/** * ========================================== * Load Configuration * ========================================== * * 1. Load clansuite.config.php * 2. Load specific staging configuration (overloading clansuite.config.php) * 3. Maintenance check * 4. Alter php.ini settings */ private static function initialize_Config() { // 1. load the main clansuite configuration file $clansuite_cfg_cached = false; if (APC === true and apc_exists('clansuite.config')) { self::$config = apc_fetch('clansuite.config'); $clansuite_cfg_cached = true; } if ($clansuite_cfg_cached === false) { self::$config = \Koch\Config\Adapter\Ini::readConfig(ROOT . 'configuration/clansuite.php'); if (APC === true) { apc_add('application.ini', self::$config); } } unset($clansuite_cfg_cached); // 2. Maintenance check if (isset(self::$config['maintenance']['maintenance']) and true === (bool) self::$config['maintenance']['maintenance']) { $token = false; // incoming maintenance token via GET if ($_GET['mnt'] !== null) { $tokenstring = $_GET['mnt']; $token = Clansuite_Securitytoken::ckeckToken($tokenstring); } // if token is false (or not valid) show maintenance if (false === $token) { Clansuite_Maintenance::show(self::$config); } else { self::$config['maintenance']['maintenance'] = 0; \Koch\Config\Ini::writeConfig(ROOT . 'configuration/clansuite.config.php', self::$config); // redirect to remove the token from url header('Location: ' . SERVER_URL); } } // 3. load staging configuration (overloading clansuite.config.php) if (true === (bool) self::$config['config']['staging']) { self::$config = \Koch\Config\Staging::overloadWithStagingConfig(self::$config); } /** * Deny service, if the system load is too high. */ if (defined('DEBUG') and DEBUG == false) { $max_load = isset(self::$config['load']['max']) ? (double) self::$config['load']['max'] : 80; if (\Koch\Functions::get_server_load() > $max_load) { $retry = (int) mt_rand(45, 90); header('Retry-After: ' . $retry); header('HTTP/1.1 503 Too busy, try again later'); die('HTTP/1.1 503 Server too busy. Please try again later.'); } } /** * ================================================ * 4. Alter php.ini settings * ================================================ */ set_time_limit(0); ini_set('short_open_tag', 'off'); ini_set('arg_separator.input', '&'); ini_set('arg_separator.output', '&'); ini_set('default_charset', 'utf-8'); self::setMemoryLimit('32'); if (false === gc_enabled()) { gc_enable(); } }