/** * testMethod_overloadWithStagingConfig() */ public function testMethod_overloadWithStagingConfig() { $array_to_overload = array('overloaded-key' => 'overloaded-value', 'error' => array('development' => '0')); $overloaded_cfg = Staging::overloadWithStagingConfig($array_to_overload); // new key exists $this->assertTrue(array_key_exists('overloaded-key', $overloaded_cfg)); // new key has correct value $this->assertEqual($overloaded_cfg['overloaded-key'], $array_to_overload['overloaded-key']); // overloading of key ['error']['development'] // original value is 0 $this->assertEqual($array_to_overload['error']['development'], '0'); // expect that error array is present $this->assertTrue(array_key_exists('error', $overloaded_cfg)); // expect that error array has a key developement $this->assertTrue(array_key_exists('development', $overloaded_cfg['error'])); // expect that this key is set to 1 (on) $this->assertEqual($overloaded_cfg['error']['development'], '1'); // expect that both values are not equal $this->assertNotEqual($overloaded_cfg['error']['development'], $array_to_overload['error']['development']); }
/** * 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; }
/** * ========================================== * 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(); } }