20) { Log::fatal('Config::replace_variables(%s): max iteration reached'); return $value; } if (is_callable($config)) $replace_by = call_user_func($config, $m[1], '', 'string', false); else $replace_by = self :: get($m[1], '', 'string', false, $config); $value = str_replace($m[0], $replace_by, $value); $iteration++; } } return $value; } /** * Get list of keys of a specific configuration variable * * @param string $key The configuration variable key * * @return array An array of the keys of a specific configuration variable **/ public static function keys($key) { $value = self :: get($key); return (is_array($value)?array_keys($value):array()); } /** * Set a configuration variable * * @param string $key The configuration variable key * @param mixed $value The configuration variable value * @param array|null &$config Optional configuration to use instead of current loaded configuration * * @return boolean **/ public static function set($key, $value, &$config=null) { $exploded_key = explode('.', $key); if (!is_array($exploded_key)) return false; if (is_array($config)) { $parent = &$config; } else { if (!is_array(self :: $config)) self :: $config = array(); $parent = &self :: $config; } for ($i=0; $i < count($exploded_key) - 1; $i++) { $k = $exploded_key[$i]; if (!array_key_exists($k, $parent)) $parent[$k] = array(); $parent = &$parent[$k]; } $parent[array_pop($exploded_key)] = $value; return true; } /** * Helper to set PHP INI option and log error * @param string $option * @param string|int|float|bool|null $value * @return void */ public static function ini_set($option, $value) { Log :: trace('Set PHP INI option "%s" to "%s"', $option, $value); if (ini_set($option, $value) === false) Log::warning('Fail to set PHP INI option "%s" to "%s"', $option, $value); Log :: trace( 'PHP INI option "%s" after setting it to "%s": "%s"', $option, $value, vardump(ini_get($option))); } } # vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab